Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a beginner in cocos2d and I wanted to display coin CCSprites as soon as it moves off the screen with a 5 second delay. So this is what I wrote in my main gameplay layer to add 7 coins in a row:

- (void)coinSidewaysRowOne { 
        if (coinSide1 == FALSE)
            coinSide1 = TRUE;
            NSLog(@"coinSide1 = TRUE");
            int originalX = 500;
            for(int i = 0; i < 8; i++)
                CCSprite *coinHorizontal = [CCSprite spriteWithFile:@"bubble.png"];
                coinHorizontal.position = ccp(originalX, 150);
                originalX += 20;

                [self addChild:coinHorizontal];
                [coinArray addObject:coinHorizontal];

And then, in my updateRunning method I added this, so when the coins spawn outside the screen, they move to the left and disappear:

// Move coins off the screen and make them move away
    for (CCSprite *coin in coinArray) {
        // apply background scroll speed
        float backgroundScrollSpeedX = [[GameMechanics sharedGameMechanics] backGroundScrollSpeedX];
        float xSpeed = 1.09 * backgroundScrollSpeedX;

        // move the coin until it leaves the left edge of the screen
        if (coin.position.x > (coin.contentSize.width * (-1)))
            coin.position = ccp(coin.position.x - (xSpeed*delta), coin.position.y);

Update: What I've tried doing is adding this below the if statement above:

else {
        coin.visible = TRUE;
        coin.position = ccp(500, 150);

So right now, when I run this, the coins move in from the right and move off the screen from the left. How do I make it so that when the coins move to the left and go off the screen, have a five second delay and then have new coins come back to the screen from the right like it originally did.

share|improve this question
What have you tried already? Do you know how to add a delay? Just write out the steps you want to do, then look up how to do each of the steps. – Byte56 Jul 19 '13 at 4:28
Check my update for what I've tried – Shalin Shah Jul 19 '13 at 4:59
up vote 1 down vote accepted

I just put my logic.

You have updateRunning method, in this method you have a logic of move coin at right to left.

Here you need to use CCMoveTo Action,

// move the coin until it leaves the left edge of the screen
if (coin.position.x > (coin.contentSize.width * (-1)))
   [coin runAction:
     [CCSequence actions: // Here set MoveDuration as you need , may be "5";
      [CCMoveTo actionWithDuration:MoveDuration position:ccp(coin.position.x - (xSpeed*delta), coin.position.y)],
      [CCCallBlockN actionWithBlock:^(CCNode *node) {
         // Here do stuff when your action is performed.

And also call your updateRunning method with specific time by using NSTimer such like, call updateRunning

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(updateRunning) userInfo:nil repeats:YES]; /// Set Time interval as you need; 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.