[Solved] How do I add and animate infinite number of objects coming from the bottom of the screen in random order in gradually increasing speeds?


I would not recommend using [NSThread sleepForTimeInterval:2];

Instead trying using [self performSelector:@selector(addBall) withObject:nil afterDelay:2];

-(void)addBall
{
    self.addedBall++;
    if (self.addedBall > 500)
    {
        return;
    }

    randomNumber = arc4random_uniform(3);

    if (randomNumber == 0) {
        [self addRedBall];
        SKAction *moveBall = [SKAction moveToY:CGRectGetMaxY(self.frame) duration:5];

        dispatch_queue_t actionDispatchRed;

        actionDispatchRed = dispatch_queue_create("com.redball.dispatch", NULL);

        dispatch_async(actionDispatchRed, ^ {   [redBall runAction:moveBall];   });

        [self performSelector:@selector(addBall) withObject:nil afterDelay:2];
    }
    //other else if stuff

}

Also I am unsure why you are running your SKActions in a dispatch_queue and is likely not needed.

I hope that helps.

8

solved How do I add and animate infinite number of objects coming from the bottom of the screen in random order in gradually increasing speeds?