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

In my game I want to have two backgrounds going one after the other creating a continuous loop moving to the left. However, right now one goes, and the other does not follow it.

Here's what I currently have, which isn't working.

if((self = [super init]))

    self.isTouchEnabled = YES;

    background=[CCSprite spriteWithFile:@"testbackground88.png"];
    [self addChild:background z:1];
    id repeat1 =[CCRepeatForever actionWithAction:[CCSequence actions:
                                                         [CCMoveTo actionWithDuration:7 position:ccp(-300,240)],
                                                         [CCPlace actionWithPosition:ccp(800,240)],nil]];
   [background runAction:repeat1];

    background2=[CCSprite spriteWithFile:@"testbackground92.png"];
    [self addChild:background2 z:1];
    id repeat2 =[CCRepeatForever actionWithAction:[CCSequence actions:
                                                         [CCMoveTo actionWithDuration:7 position:ccp(-300,240)],
                                                         [CCPlace actionWithPosition:ccp(800,240)],nil]];
   [background2 runAction:repeat2];
share|improve this question

Basically you are running both actions at the same exact time. Your code does not "wait" for an action to end before continuing, it simply starts both animations. If you want to wait for one action to end before calling the next animation, you will have to look in to the CCCallFunc or CCCallBlock classes, which basically allow you to insert a function or block into your action sequence.

Then again, you may not want to be using actions for something like this at all. You could just as easily control the background movement manually inside of an update method.

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.