Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKSpriteNode will not fadeInWithDuration using SKAction in sequence Sprite Kit

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];
}
like image 388
Stefan Avatar asked Feb 06 '14 14:02

Stefan


1 Answers

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.

like image 189
Batalia Avatar answered Nov 15 '22 00:11

Batalia