Question

How do I move a sprite automatically back after dragging it somewhere on the screen?

I tried:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        CGPoint newPosition = CGPointMake(location.x, self.size.height/2);
        self.start.position = newPosition;
        }
    SKAction *moveTo = [SKAction moveToX:self.frame.size.width/2 duration:0.5];
    [self.start runAction:moveTo];
}
Was it helpful?

Solution

If you use moveByX:y:duration: to initially move your sprite, you can then use [yourActionName reversedAction]; to move it back to the initial starting point when touchesEnded:.

OTHER TIPS

You can use the -(void)touchesMoved: to place the sprite. Then use -(void)touchesEnded: method to move it back to its origin point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top