Good afternoon,

For the past few days I've been making a game very similar to DoodleJump in the sense that it involves a main character, things to jump on, certain powerups and some monsters. I've pretty much laid the foundation for everything I need except for one thing. And no, I'm not going to release this game on the app store for publicity, nor do I plan on trying to claiming it as my own game, since the entire game borrows from DoodleJump. I am creating this game as a practice project for myself.

I need some way to implement the "infinite" vertical scrolling that appears in DoodleJump. I've tried several things and searched through many forums and discussion pages, but I can't seem to find one.

Here's some of things I've tried:

- (void) followPlayer
   static CGSize winSize = [[CCDirector sharedDirector]winSize];
   static float fixedPos = winSize.height * .25;
   CCLOG(@"Fixed pos: %f",fixedPos);
   float newY = fixedPos - mainPlayer.position.y;    // mainPlayer
                                                  is a custom object I created
   newY = MIN(newY,fixedPos);
   newY = MAX(newY,-maxHeight - fixedPos); // maxHeight is a float
                                             that keeps track of how high in (y)
                                             coordinates the map is. i.e
                                             every time I add something to the map,
                                             I increment this counter to account
                                             for the new object's height.

   CGPoint pos = ccp(self.position.x,newY);
   [self setPosition:pos];


That method gets called in my update method, so it's supposed to position the screen to follow the character, however it doesn't work as expected. The screen shifts slightly up even when the character hasn't passed the 25% margin that I defined, some static bodies that I created with Box2D also get all messed up.

Is there any other thing I can implement to achieve the "infinite" vertical scroll? I really hit a brick wall on this one, any suggestions would be greatly appreciated.

Edit Here's the code for the failing scrolling background.

This is my BackgroundLayer class that contains the background images:

- (id) init
   self = [super init];

     back1 = [CCSprite spriteWithFile:@"Background.png"];
     back1.anchorPoint = ccp(0,0);
     [back1 setPosition:ccp(0,0)];

     [self addChild:back1];
     [self scheduleUpdate];

   return self;
- (void) update:(ccTime) dt

    CGPoint b1 = [back1 position];
    b1 = [[self parent] convertToNodeSpace:b1];
    if(b1.y < 0)
        back1.position = ccp(0,back1.contentSize.height);


This class is then being added as a child in my HelloWorldLayer class as the variable layer, which gets scrolled as the player moves up.

  • \$\begingroup\$ Are you wanting to create infinite scrolling or just make it scroll? Because in your question you say you can't get it to scroll but you also say you just want infinite scrolling... How do you create your background? Do you use tiles? Do you use an image with images placed at certain points for platforms?? \$\endgroup\$ – Savlon Feb 18 '13 at 19:51
  • \$\begingroup\$ Sorry for the lack of information I gave. I CAN get it to scroll just not "infinitely" I am using a background image which all it is doing is "replacing" itself once its y coordinate reaches -1. I can't get this "infinite" scroll to work. \$\endgroup\$ – Alejandro Feb 18 '13 at 19:53
  • \$\begingroup\$ So you can't get the background image to move to the top of the screen to re-commence its journey back down? I still am not understanding your problem... I know now you can't get it infinite. Why though? What does it do? \$\endgroup\$ – Savlon Feb 18 '13 at 19:57
  • \$\begingroup\$ In the initial launch of the game the scrolling works fine. The background image scrolls up like its supposed to. However, once it scrolls past its max height ( 2048px) it doesn't come back up, the screen just stays black. The issue I am having is that the background image won't come back down. \$\endgroup\$ – Alejandro Feb 18 '13 at 20:00
  • \$\begingroup\$ Ahh I see... That makes sense now :) ok well what happens when you set the background image back to its starting location once it has reached the end? \$\endgroup\$ – Savlon Feb 18 '13 at 20:49

Browse other questions tagged or ask your own question.