我一直在研究如何根据用户触摸屏幕的位置调用不同的触控方式。我认为这在Sprite Kit中应该相当简单,但我找不到任何内容。目前我正在使用以下内容来使角色跳跃。
如果触摸屏幕的左侧或右侧,我该如何使用此方法?所以正确的触摸调用一种方法,左触摸调用另一种方法。感谢。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
if (isJumping == NO){
isJumping = YES;
SKSpriteNode* charNode = (SKSpriteNode*)[self childNodeWithName:@"character"];
[charNode runAction:jumpAnimation];
[charNode runAction:jumpMovement];
}
}
答案 0 :(得分:0)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self.scene];
if(touchLocation.x < self.size.width/2)
NSLog(@"left side");
if(touchLocation.x > self.size.width/2)
NSLog(@"right side");
}