顺序动作有问题

时间:2014-11-15 00:27:21

标签: objective-c sprite-kit fade skaction

我希望我的菜单在等待几秒后淡入视图。我尝试将动作序列放在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;
}

1 个答案:

答案 0 :(得分:0)

正如评论中所提到的,这不起作用,因为没有什么可以“淡入”。

来自the documentation

  

当动作执行时,节点的alpha属性会将 从当前值 设置为1.0。

请注意我强调的部分,当您创建SKSpriteNode时,它的alpha将为1.0,因此您需要在实例化之后首先将其设置为0:

titleBreaker.alpha = 0;

然后您的[SKAction fadeInWithDuration:5]将有效。