How to get a callback from a repeating SpriteKit action when a sprite reaches the end of the path?

I created mine SKActionas follows:

unicornAction = [SKAction followPath:mypath asOffset:NO orientToPath:YES duration:0.1];

and added it to mine SKSprite:

[sprite runAction:[SKAction repeatActionForever:unicornAction] withKey:@"move"];

I do this so that I can adjust the speed at any time within the movement of sprites along the way.

When my sprite reaches the end of the path, I need a callback to remove the sprite. How can I get such a callback?

Also, is there a better way to use SKActionto accomplish what I'm trying to do, letting me change the speed anywhere during the execution of the actions?

+4
source share
2 answers

runBlock Selector :

SKAction* sequence = [SKAction sequence:@[unicornAction, [SKAction runBlock:^{
    // code at end of path goes here...
}]];

[sprite runAction:sequence withKey:@"follow path"];

:

SKAction* sequence = [sprite actionForKey:@"follow path"];
+8

All Articles