I'm trying to do a simple automatically reversing animation.
SKAction *a = [SKAction moveToX:10 duration:0.5];
a = [SKAction repeatActionForever:a];
[car runAction:a];
But the action doesn't reverse. How do you get a similar autoreverse effect like with Core Animation?
Answer from Andrey Gordeev is close enough,
float x = car.position.x;
SKAction *a = [SKAction moveToX:(x+10) duration:0.5];
SKAction *b = [SKAction moveToX:x duration:0.5];
SKAction *seq = [SKAction sequence:@[a,b]];
[car runAction:[SKAction repeatActionForever:seq]];
moveToX:(x+10) will make it swing by 10 (instead of go at point X=10).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With