Question

I am trying to create a box that flies to the centre of the scene whilst fading in, however the SKAction never seems to be run, any ideas why?

-(void)update:(CFTimeInterval)currentTime {
    CFTimeInterval delta = currentTime - _previousUpdateTime;

    _previousUpdateTime = currentTime;

    if (playerLives == 0 && isGameOver == NO) {
        [self endGame];
        [self moveBallToStartingPosition];
        [self displayGameResults];
    }
}

....

-(void)displayGameResults {

    SKLabelNode *result = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
    result.color = [UIColor redColor];
    result.fontSize = 20;
    result.name = @"gameResultsLabel";
    result.text = [NSString stringWithFormat:@"Game over! score: %d", playerScore];

    SKSpriteNode *container = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:[result calculateAccumulatedFrame].size];
    container.alpha = 0.3;
    container.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame));
    [container addChild:result];

    SKAction *moveTo = [SKAction moveTo:CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) duration:3.0];
    SKAction *fadeIn = [SKAction fadeInWithDuration:3.0];

    [container runAction:moveTo];
    [container runAction:fadeIn];

    [self addChild:container];
}

The actions do not run if I apply them to the SKLabelNode either.

EDIT: Nowhere in the code are there any calls to remove actions. I'm at a loss why they are not firing!

Was it helpful?

Solution

I figured out what it is that is causing it, it was a line of code in my endGame function that set the physics world speed to 0

-(void)endGame {

    isGameOver = YES;

    self.speed = 0.0;
}

commenting out self.speed = 0.0 fixes the issue. Whoops...

OTHER TIPS

Do not run actions in this way

If you want them to work in a sequence then use sequence action

SKAction *sequence = [SKAction sequence:@[moveTo,fadeIn]];
[container runAction:sequence];

If you want them to work simultaneously then use group action

SKAction *group = [SKAction group:@[moveTo,fadeIn]];
[container runAction:group];

Let me know if this didn't solve your problem ... However you should do the actions in this way


Update

After you added your update: please be sure that Condition playerLives == 0 && isGameOver == NO is true only one time. as Your update: can be called 60 times in a single second which will lead to result be created 60 time in a second

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top