user3808710
user3808710

Reputation: 27

SKAction method fadeInWithDuration Not Working

I am working on making a Ball Node appear and I add the ball Node with the alpha set to 0.01 and in the documentation fadeInWithDuration should make the alpha 1.0. I put a break point and the method is being called but it is not making the ball node appear.

-(void)addBallToFrame {
    _ballNode = [SKSpriteNode spriteNodeWithImageNamed:@"Ball"];
    SKAction *ballPosition = [SKAction runBlock:^(void) {
        _ballNode.position = CGPointMake(CGRectGetMidX(self.frame), 295*ratio);
        [_ballNode setZPosition:10];
        [_ballNode setAlpha:0.01];
        [self addChild:_ballNode];
    }];
    SKAction *timeForBallToAppear = [SKAction waitForDuration:1.5];
    SKAction *changeAlpha = [SKAction fadeInWithDuration:0.5];
    SKAction *ballAppearSequence = [SKAction sequence:@[timeForBallToAppear, ballPosition, changeAlpha]];   
    [self runAction:ballAppearSequence];
    _ballNode.zPosition = 10;
    [_ballNode setPhysicsBody:[SKPhysicsBody bodyWithCircleOfRadius:_ballNode.frame.size.height / 2.0]];
    _ballNode.physicsBody.categoryBitMask = BALL_CATEGORY;
    _ballNode.physicsBody.collisionBitMask = WALL_CATEGORY | PLAYER_ONE_CATEGORY | PLAYER_TWO_CATEGORY | GOAL_POST_CATEGORY;
    _ballNode.physicsBody.contactTestBitMask = GOAL_ONE_CATEGORY |GOAL_TWO_CATEGORY;
    _ballNode.physicsBody.friction = 0.0;
    _ballNode.physicsBody.linearDamping = 0.0;
}
-(void)removeBallFromFrame {
    _ballNode.position = CGPointMake(-100, -100);
    [self.ballNode removeFromParent];
}

Upvotes: 1

Views: 151

Answers (1)

Andrey Gordeev
Andrey Gordeev

Reputation: 32459

That's because you run changeAlpha action on self, instead of _ballNode. Try to change

 [self runAction:ballAppearSequence];

to

 [_ballNode runAction:ballAppearSequence];

Upvotes: 1

Related Questions