【发布时间】:2014-09-16 15:37:48
【问题描述】:
在使用 iOS SpriteKit 开发我的新游戏时,我正在尝试制作一个简单的左右控制器来在屏幕上移动我的角色。我就是这样做的。这是一个 SKScene 实现。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < [UIScreen mainScreen].applicationFrame.size.width/2) {
_leftPressed = YES;
} else if (touchLocation.x > [UIScreen mainScreen].applicationFrame.size.width/2){
_rightPressed = YES;
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
_leftPressed = NO;
_rightPressed = NO;
}
-(void)update:(CFTimeInterval)currentTime {
if (_rightPressed) {
[self.player.physicsBody applyForce:CGVectorMake(speed, 0)];
} else if (_leftPressed) {
[self.player.physicsBody applyForce:CGVectorMake(-speed, 0)];
} else {
}
}
很快,我发现这种控制我的角色的方法有问题。如果我同时按下一根手指并松开另一根手指来改变方向,角色就会停止并且不会改变方向。我想这是因为方法- (void) touchesBegan 和方法- (void) touchesEnded 不能同时调用。我希望我的控制器真正灵敏并且能够流畅地处理多点触控。我该如何进行这项工作?有没有解决这个问题的好方法?
【问题讨论】:
标签: ios xcode ios7 sprite-kit game-physics