我有一个游戏,我想根据用户触摸屏幕的左侧或右侧来向左或向右移动SKNode。如何在用户触摸屏幕时对节点应用恒定移动?
发布于 2014-08-02 20:02:16
如果您的SKNode具有physicsBody,请对其施加强制:
@interface GameScene()
@property (nonatomic) CGVector force;
@end
@implementation GameScene
- (void)update:(CFTimeInterval)currentTime {
[self.player.physicsBody applyForce:self.force];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.sideForce = CGVectorMake(3000, 0);
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.sideForce = CGVectorMake(0, 0);
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
self.sideForce = CGVectorMake(0, 0);
}
@end如果没有,请使用LearnCocos2D的答案。
https://stackoverflow.com/questions/19286610
复制相似问题