0

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

我正在尝试使用 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 图像。

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

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

谢谢。

4

1 回答 1

3

我对此不是 100% 确定,但我认为你应该做一系列事件,而不是调用 sleep()。

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


}
于 2014-01-14T21:56:55.277 回答