Вопрос

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];
}
Это было полезно?

Решение

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:.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top