如何让SKNode
继续前进?
我已经能够使用[SKAction moveByX:y:duration:]
让节点沿固定方向移动,但我希望它沿相对于其面向的方向移动。
我希望每个节点转45度然后“向前走”50像素。
看起来很简单,我无法找到它。
答案 0 :(得分:2)
这将旋转,然后朝你点击的位置
-(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]
]]];
}
}
}
答案 1 :(得分:0)
我也考虑过这一点。我想在继续之前创建一个似乎正在转动的节点。我考虑过这样做的一种方法是让一个子节点附加在场景中移动的节点的“最前面”部分。然后我会计算子节点的抽头距离。那有意义吗?基本上,我可以从场景中任何位置的点击计算节点的前端。