我正在製作一個遊戲,玩家一次移動兩個數字。每個人都有自己的一半屏幕,並在內部移動。不幸的是,我發現,當我用拇指滑動時,什麼都沒有發生。甚至連我的一個識別器都沒有被觸發。模擬獨立手勢
也許有一種方法。我在GameViewController的頂部創建了另外兩個視圖並添加了單獨的手勢。但我無法在我的gamescene.m中向他們作出反應來創建動作。
是否有無論如何承認在GameViewControl中GameScene中聲明的滑動,並添加到他們的任何操作?
我已經試圖根據觸摸開始並結束我自己的識別器,但是當兩個手指一次被釋放時它變得混亂並且通常忘記反應兩次,我的意思是分別爲每個版本。
-(void)setUpGestActions{
_swipeGestureLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft:)];
[self.swipeGestureLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
self.swipeGestureLeft.cancelsTouchesInView = NO;
self.swipeGestureLeft.delegate = self;
[self.view addGestureRecognizer: self.swipeGestureLeft];
_swipeGestureRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight:)];
[self.swipeGestureRight setDirection:UISwipeGestureRecognizerDirectionRight];
self.swipeGestureRight.cancelsTouchesInView = NO;
self.swipeGestureRight.delegate = self;
[self.view addGestureRecognizer: self.swipeGestureRight];
_swipeGestureUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeUp:)];
[self.swipeGestureUp setDirection:UISwipeGestureRecognizerDirectionUp];
self.swipeGestureUp.cancelsTouchesInView = NO;
self.swipeGestureUp.delegate = self;
[self.view addGestureRecognizer: self.swipeGestureUp];
_swipeGestureDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown:)];
[self.swipeGestureDown setDirection:UISwipeGestureRecognizerDirectionDown];
self.swipeGestureDown.cancelsTouchesInView = NO;
self.swipeGestureDown.delegate = self;
[self.view addGestureRecognizer: self.swipeGestureDown];
_moveLeft = [SKAction moveByX:-self.frame.size.width/6 y:0 duration:self.velocity];
_moveRight = [SKAction moveByX:self.frame.size.width/6 y:0 duration:self.velocity];
_moveUp = [SKAction moveByX:0 y:self.frame.size.width/6 duration:self.velocity];
_moveDown = [SKAction moveByX:0 y:-self.frame.size.width/6 duration:self.velocity];
_downMovement = [SKAction moveByX:0 y:-1 duration:self.downMovementVelocity];
}
-(void)swipeLeft:(UISwipeGestureRecognizer*) recognizer{
_sideDisting = [recognizer locationInView:self.view];
if(self.sideDisting.x <= self.frame.size.width/2){
[_boy runAction:self.moveLeft];
}
else{
[_girl runAction:self.moveLeft];
}
}
-(void)swipeRight:(UISwipeGestureRecognizer*) recognizer{
_sideDisting = [recognizer locationInView:self.view];
if(self.sideDisting.x <= self.frame.size.width/2){
[_boy runAction:self.moveRight];
}
else{
[_girl runAction:self.moveRight];
}
}
-(void)swipeUp:(UISwipeGestureRecognizer*) recognizer{
_sideDisting = [recognizer locationInView:self.view];
if(self.sideDisting.x <= self.frame.size.width/2){
[_boy runAction:self.moveUp];
}
else{
[_girl runAction:self.moveUp];
}
}
-(void)swipeDown:(UISwipeGestureRecognizer*) recognizer{
_sideDisting = [recognizer locationInView:self.view];
if(self.sideDisting.x <= self.frame.size.width/2){
[_boy runAction:self.moveDown];
}
else{
[_girl runAction:self.moveDown];
}
}
我已經這樣做了,但沒有任何結果。將interface和bool中的delegate設置爲YES,您也可以看到self.swipeGestureDown.delegate = self;在每個分配代碼塊中行。我認爲它與其他一些識別器一樣,比如雙擊或其他。 (我沒有在我的代碼中聲明這樣的事情) –