我按顺序运行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]; }
解决方法
如
documentation中所述,fadeInWithDuration操作将节点的alpha属性从其当前值更改为1.0(100%不透明度).
这就是为什么你没有看到淡入 – 你的动作实际上不会做任何事情,因为节点的默认alpha值是1.0,它将从100%变为100%.
正如Steffen在他的评论中建议的那样,你需要做的就是在执行动作之前设置buttonStart.alpha = 0.0.