2014-04-04 60 views
0

我有一个精灵,我可以在屏幕上拖动。我的问题是如何使它也自动旋转。SpriteKit根据触摸位置旋转精灵

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if(_dead) 
     return; 

    NSArray *touchArray=[touches allObjects]; 
if ([touchArray count] == 1) 
    { 
     [_player runAction:[SKAction moveTo:[[touches anyObject] locationInNode:self] duration:0.01]]; 
    } 

} 

目前这是我的代码,它是完美的draging。

+0

旋转到它正在移动的方向? – ZeMoon

回答

0

如果要在同一方向每次只需调用

_player.zRotation = valueBetween_0_and_1_ 

SKAction *rotation = [SKAction rotateByAngle: ANGLE duration:DURATION]; 

然后,您可以写一个方法来旋转精灵取决于它的起源或移动方向。

+0

好的,但如何获得触摸位置的当前角度。因为当我拖动角度每0.01秒改变一次。 – user1621978

+0

您应该通过zRotation获取此信息。 – Akaino