0
votes

Using SpriteKit, I have created a sprite, and would like to display the sprite, pause for a second, then begin the animation using a new sprite.

Currently, I am using

self.neko = [SKSpriteNode spriteNodeWithImageNamed:@"Awake.ico"];
[self addChild:self.neko];

sleep(2);

[self.neko removeFromParent];

Based on the code provided, you would think the sprite would be drawn, then the thread would sleep for a couple of seconds, and then remove the sprite from the parent.... but the sprite is not being shown.

If I remove the removeFromParent line, the sprite will remain on the screen.

So the question is this, am i doing it correctly?

Is there a way to force the sprite to be updated on the scene before the sleep timer is executed?

1
sleep() will just freeze the entire app - LearnCocos2D

1 Answers

0
votes

You could use an SKAction like this to display the sprite for two seconds and then remove it:

[self.neko runAction:
     [SKAction sequence:@[
         [SKAction waitForDuration:2.0],
         [SKAction removeFromParent]
     ]]
];