Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2D vertically scrolling background
    primarykey
    data
    text
    <p>I have three images (320x480) that I'm trying to scroll vertically in my Cocos2D application. </p> <p>In my initialization method, I have the following:</p> <pre><code>//adding background sprites background = [CCSprite spriteWithFile:@"BG1.png"]; background2 = [CCSprite spriteWithFile:@"BG2.png"]; //position background sprites background.position = ccp(size.width, size.height/2); background2.position = ccp(size.width, size.height*2); //schedule to move background sprites [self schedule:@selector(scroll:)]; //adding them to the main layer [self addChild:background z:0]; [self addChild:background2 z:0]; </code></pre> <p>And here's my scroll method:</p> <pre><code>-(void) scroll:(ccTime)dt { //move 30*dt px vertically background.position = ccp(background.position.x, background.position.y - 30*dt); background2.position = ccp(background2.position.x, background.position.y - 30*dt); //reset offscreen position if (background.position.y &lt; 290) { background.position = ccp(480/2, 480); }else if (background2.position.y &lt; 290) { background2.position = ccp(480/2,480); } } </code></pre> <p>Currently what's happening is my first background image is offset by about a quarter of the screen (horizontally), and it starts a quarter of the way up from the bottom of the screen, but it scrolls down. My second background image doesn't actually spawn, the first image just loops over and over while being offset. Is there any way to make the two images smoothly loop continuously in the background, and how would I incorporate a third image?</p> <p>Also, just a quick side question, is it bad to name objects (I think they're objects) with numbers in their name (ie background2/background3)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload