2013-10-04 47 views
2

如何获得SKNode前进?SKAction向前移动

我已经能够使用[SKAction moveByX:y:duration:]使节点在固定方向上移动,但我希望它能够沿相对于它所面对的方向的方向移动。

我正在寻找使每个节点转向45度,然后“走”向前50个像素。

这似乎很简单,我只是无法找到它。

回答

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] 
           ]]]; 
    } 
} 
} 
0

我曾想过这一点。我想在继续之前创建一个似乎可以转向的节点。我已经考虑过这样做的一种方法是让子节点附加在场景中移动的节点的“最前面”部分。然后我会计算点击形式的子节点的距离。那有意义吗?从本质上讲,我将能够从场景中的任意位置轻敲节点来计算节点的前端。

相关问题