我希望我的菜单在等待几秒后淡入视图。我尝试将动作序列放在initWithSize方法和sprite本身中,但它根本不起作用。有人可以检查我的代码并告诉我它有什么问题吗?
-(void) addTitleBreaker:(CGSize)size {
SKSpriteNode *titleBreaker = [SKSpriteNode spriteNodeWithImageNamed:@"titleBreaker"];
//resize title breaker
titleBreaker.size = CGSizeMake(titleBreaker.size.width/2, titleBreaker.size.height/2);
//position title breaker
CGPoint myPoint = CGPointMake(180, 364);
titleBreaker.position = myPoint;
//add action
/*SKAction *wait = [SKAction waitForDuration:5];
SKAction *fadeIn = [SKAction fadeInWithDuration:5];
SKAction *sequence = [SKAction sequence:@[wait,fadeIn]];
[titleBreaker runAction:sequence];*/
[self addChild:titleBreaker];
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor colorWithRed:(29.0f/255) green:(29.0f/255) blue:(29.0f/255) alpha:1.0];
//create fade in action
/*SKAction *wait = [SKAction waitForDuration:5];
SKAction *fadeIn = [SKAction fadeInWithDuration:5];
SKAction *sequence = [SKAction sequence:@[wait,fadeIn]];
[self runAction:sequence];*/
[self addTitleBrick:size];
[self addTitleBreaker:size];
[self addPlayButton:size];
[self addLeaderboards:size];
[self AddHighScoreLabel:size];
[self addInfoLogo:size];
[self addSoundLogo:size];
[self addMusicLogo:size];
}
return self;
}
答案 0 :(得分:0)
正如评论中所提到的,这不起作用,因为没有什么可以“淡入”。
当动作执行时,节点的alpha属性会将 从当前值 设置为1.0。
请注意我强调的部分,当您创建SKSpriteNode
时,它的alpha将为1.0
,因此您需要在实例化之后首先将其设置为0:
titleBreaker.alpha = 0;
然后您的[SKAction fadeInWithDuration:5]
将有效。