1
votes

I have an SKScene where I am adding an SKSpriteNode. I have subclassed SKSpriteNode class to create this node. In the subclass i am defining certain SKActions on the sprite. What i want is that when the SKAction sequence that runs on this sprite ends, i add a new sprite node to the scene. How is this possible. Following is my code:

code for sequence that i am running on skspritenode subclass (TEMissileNode) :-

SKAction *moveDown = [SKAction moveToY:self.position.y - 20 duration:0.2];

SKAction *animation = [SKAction animateWithTextures:textures timePerFrame:time/7];

SKAction *moveMissileProjectile = [SKAction moveTo:pointoffScreen duration: time];

SKAction *group = [SKAction group:@[animation, moveMissileProjectile]];

SKAction *sequence = [SKAction sequence : @[moveDown,group, [SKAction removeFromParent]]];

[self runAction:sequence];

From the main scene I am calling the method which executes these actions

 TEMissileNode *missile = [TEMissileNode missileAtPoint: CGPointMake(copter.position.x + copter.size.width/2, copter.position.y - 20)
                                                     Type:TEMissileTypeA];



    [self addChild:missile];
    [missile moveTowardsPosition:position];

What i want is that after the completion of the method (moveTowardsPosition:position), I add another child sprite node to the scene but how to get a completion notification from the method.

1

1 Answers

1
votes

There are two ways of going about calling code after the completion of an action.

Use the completion block after runAction.

[self runAction:sequence completion:^{
    //Add relevant code here.
}];

Or, add another block to execute at the end of the sequence.

SKAction *actionBlock = [SKAction runBlock:^{
    //Add relevant code here.
}];
SKAction *sequence = [SKAction sequence : @[moveDown,group, [SKAction removeFromParent], actionBlock]];