SKSpriteNode will not fadeInWithDuration using SKAction in sequence Sprite Kit

Stefan picture Stefan · Feb 6, 2014 · Viewed 8.5k times · Source

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?

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

Answer

Batalia picture Batalia · Feb 6, 2014

As stated in the documentation, the fadeInWithDuration action changes the alpha property of the node from its current value to 1.0 (100% opacity).

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%.

As Steffen has suggested in his comment, all you need to do is set buttonStart.alpha = 0.0 before the action is executed.