SpriteKit runAction and updating count?

Discussion in 'iOS Programming' started by trey5498, Apr 7, 2014.

  1. trey5498 macrumors regular

    Joined:
    Jun 16, 2008
    #1
    I am currently attempting to complete a school project that uses SpriteKit. Since we are not given much time we were asked to create or modify the existing one from the book (Archer hitting balloons). I have successfully created a score hud display and I want to add the balls left to drop.

    Here is what is in the book,

    Code:
    SKAction *releaseBalls = [SKAction sequence:@[[SKAction performSelector:@selector(createBallNode) onTarget:self], [SKAction waitForDuration:1]]];
    
        [self runAction: [SKAction repeatAction:releaseBalls count:self.ballCount] completion:^{
            [self gameOver];
        }]; 
    
    What I am trying:

    Code:
    _ballsLeft = 40;
    while (_ballsLeft <0)
    {
         [self runAction:releaseBalls completion:^{
            [self gameOver];
        }];
        _ballsLeft--;
        _ballsLeftLabel.text = [NSString stringWithFormat:@"Balls Left: %04d", _ballLeft];
    } 
    
    
    I am sure there is a better way to accomplish this, especially since mine does update or drop any balls.

    Can anyone help?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Think very carefully about what the red-hilited statements mean. Pay particular attention to the condition of the 'while'. Step through it using pencil and paper if necessary.
     
  3. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #3

    Sorry that was a typo supposed to be while (_ballsLeft > 0).
     

Share This Page