如何让 SKNode
继续前进?
我已经能够使用 [SKAction moveByX:y:duration:]
让节点沿固定方向移动,但我希望它沿相对于其面向方向的方向移动.
我希望让每个节点旋转 45 度,然后向前“行走”50 像素。
看起来很简单,我只是找不到它。
最佳答案
它将旋转,然后朝着您点击的位置旋转
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
CGPoint diff = CGPointMake(location.x - _myPlayer.position.x, location.y - _myPlayer.position.y);
CGFloat angleRadians = atan2f(diff.y, diff.x);
[_myPlayer runAction:[SKAction sequence:@[
[SKAction rotateToAngle:angleRadians duration:1.0],
[SKAction moveByX:diff.x y:diff.y duration:3.0]
]]];
}
}
}
关于ios - SKA行动向前推进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19172140/