SKAction似乎没有起作用

时间:2013-10-25 21:34:29

标签: objective-c ios7 sprite-kit skaction

我正在使用精灵套件制作游戏。我创建了一个菜单屏幕,用户按下按钮转换到下一个场景,我想在按下按钮时设置动画。

我正在尝试使用SKAction来执行此操作,我编写了此代码但是当我按下按钮时没有动画。

(我知道问题不在于这个代码没有运行,因为当按下按钮时,向下一个场景的转换完全按照预期工作,除了按钮动画不播放)

(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];
}

如果有帮助,playGameButton是SKSpriteNode,它是.png图像。

我目前正在模拟器上运行它。

非常感谢任何建议的帮助。我很确定这对经验丰富的人来说是一件相当明显的事情。

感谢。

1 个答案:

答案 0 :(得分:3)

我不是100%肯定这个,而不是叫睡眠()我认为你应该做一系列事件。

(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]]];


}