Reputation: 185
I am making a game using sprite kit. I have created a menu screen where the user presses a button to transition to the next scene, and I want to animate the button when it is pressed.
I am trying using an SKAction to do this, I have written this code but no animation occurs when I press the button.
(I know that the problem is not that this code is not being run, as the transition to the next scene works exactly as expected when the button is pressed, except the button animation does not play)
(void)runMenuTransition
{
//Animation for the button, the problem is that this doesn't seem to work
SKAction *buttonAnimation = [SKAction fadeAlphaBy:0.5 duration:0.2];
[self.playGameButton runAction: buttonAnimation];
sleep(1);
//Transition to the next scene (this part seems to work fine)
SKTransition *reveal = [SKTransition fadeWithDuration:0.75];
EclipseSecondMenuScene *newScene = [[EclipseSecondMenuScene alloc]initWithSize:self.size];
[self.scene.view presentScene:newScene transition:reveal];
}
If it helps, playGameButton
is an SKSpriteNode and it is a .png image.
I am currently running this on the simulator.
Any help of suggestions is much appreciated. I am pretty sure that this is a fairly obvious thing to someone who is experienced.
Thanks.
Upvotes: 0
Views: 449
Reputation: 677
I am not 100% sure on this but rather than calling sleep() i think you should just do a sequence of events.
(void)runMenuTransition
{
//Animation for the button, the problem is that this doesn't seem to work
SKAction *buttonAnimation = [SKAction fadeAlphaBy:0.5 duration:0.2];
SKAction *wait = [SKAction waitForDuration:1];
SKAction *transition = [SKAction runBlock:^{
//Transition to the next scene
SKTransition *reveal = [SKTransition fadeWithDuration:0.75];
EclipseSecondMenuScene *newScene = [[EclipseSecondMenuScene alloc]initWithSize:self.size];
[self.scene.view presentScene:newScene transition:reveal];
}];
[self.playGameButton runAction: [SKAction sequence:@[buttonAnimation,wait,transition]]];
}
Upvotes: 3