我正在制作一个有东西在移动的精灵游戏,我想这样做,如果我触摸屏幕的右半部分,它会右转,如果我触摸左半部分,它会左转。我怎样才能不断地在屏幕上找到所有触摸的地方?
最佳答案
你应该能做如下事情
目标C
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.frame.size.width / 2) {
// Left side of the screen
} else {
// Right side of the screen
}
}
斯威夫特
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch:UITouch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
if touchLocation.x < self.frame.size.width / 2 {
// Left side of the screen
} else {
// Right side of the screen
}
}
关于ios - 如何检查SpriteKit的任一半屏是否触摸?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24899828/