xcode SKSpriteNode 不会在 Sprite Kit 中使用 SKAction 进行淡入淡出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21605570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SKSpriteNode will not fadeInWithDuration using SKAction in sequence Sprite Kit
提问by Stefan
Im running 3 SKActions in a sequence, the 1st two run just fine but the fadeInWithDuration does not fade in the node, the node just gets added right away when the view loads. Do I have to set the the initial alpha channel for the node to 0? Can someone help with problem?
我按顺序运行 3 个 SKActions,第一个两个运行得很好,但fadeInWithDuration 不会在节点中淡出,节点会在视图加载时立即添加。我是否必须将节点的初始 alpha 通道设置为 0?有人可以帮忙解决问题吗?
- (void)setUpButtonStart
{
SKSpriteNode *buttonStart = [SKSpriteNode spriteNodeWithImageNamed:@"start"];
buttonStart.name = @"buttonStart";
buttonStart.position = CGPointMake(900,50);
[self addChild:buttonStart];
SKAction *wait = [SKAction waitForDuration:2.5];
SKAction *readIntro = [SKAction playSoundFileNamed:@"intro.mp3" waitForCompletion:NO];
SKAction *fadeIn = [SKAction fadeInWithDuration:1.0];
SKAction *sequence = [SKAction sequence:@[wait, readIntro, fadeIn]];
[buttonStart runAction: sequence];
}
回答by Batalia
As stated in the documentation, the fadeInWithDuration
action changes the alpha
property of the node from its current valueto 1.0 (100% opacity).
如文档中所述,该fadeInWithDuration
操作alpha
将节点的属性从其当前值更改为 1.0(100% 不透明度)。
That's why you're not seeing the fade-in - your action will not actually do anything, since the default alpha value of a node is 1.0, it will go from 100% to 100%.
这就是为什么您没有看到淡入 - 您的操作实际上不会执行任何操作,因为节点的默认 alpha 值为 1.0,它将从 100% 变为 100%。
As Steffen has suggested in his comment, all you need to do is set buttonStart.alpha = 0.0
before the action is executed.
正如 Steffen 在他的评论中所建议的那样,您需要做的就是buttonStart.alpha = 0.0
在执行操作之前进行设置。