0
votes

I have a sprite which I can drag across the screen. My question is how to make it also to rotate automatically.

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

}

Currently this is my code and it is working perfectly for draging.

1
rotate to the direction it is moving to? - ZeMoon

1 Answers

0
votes

If it shall in the same direction every time you can just call

_player.zRotation = valueBetween_0_and_1_

or

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

You can then write a Method to rotate the sprite depending on it's origin or move direction.