【发布时间】:2015-04-21 14:29:01
【问题描述】:
如果你愿意的话,我目前正在开发某种自上而下的赛车。这个想法是有两个按钮,每个按钮用于向左或向右转动汽车。这一切都有效,但它只适用于一键式。我想让玩家通过简单地按住按钮来转动汽车。我现在有
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
touched = YES;
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if ([node.name isEqualToString:@"buttonLeft"]) {
while (touched == YES) {
playerRotate = player.zRotation;
playerRotate += playerAngle;
}
}
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
player.zRotation = playerRotate;
float dx = playerSpeed * cos(player.zRotation);
float dy = playerSpeed * sin(player.zRotation);
player.physicsBody.velocity = CGVectorMake(dx, dy);
}
玩家汽车的速度在更新功能中更新。并且在touchesEnded touches 中设置为NO。问题是这个while循环卡住了(我的手机不再进行任何触摸),但我不知道只要按下按钮就可以继续旋转汽车。如果我删除 while 循环,该代码将起作用。任何帮助表示赞赏!
【问题讨论】:
标签: objective-c rotation sprite-kit touchesbegan