[solved]problem with scrolling background

Hi, I used this code to create a scrolling background with 7 images, the problem is that it display just 2 images instead of 7, how can I fix it? thanks

[code]
local bg1 = display.newImage(“backGround01.png”, 0, 0); – place bg1 at the origin
local bg2 = display.newImage(“backGround02.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg3 = display.newImage(“backGround03.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg4 = display.newImage(“backGround04.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg5 = display.newImage(“backGround05.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg6 = display.newImage(“backGround06.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg7 = display.newImage(“backGround07.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
–local bg8 = display.newImage(“backGround08.png”, 0, bg2.y + (bg2.height * 1.5));
–bg1.x,bg2.x = 160,160
local moveBG = function(e)
bg1:translate(0, bgSpeed); – move bg1 bgSpeed on the y plane
bg2:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg3:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg4:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg5:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg6:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg7:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane

if ((bg1.y - bg1.height / 2) > display.contentHeight) then
bg1.y = bg2.y - bg2.height;

elseif((bg2.y - bg2.height / 2) > display.contentHeight) then
bg2.y = bg1.y - bg1.height;

elseif((bg3.y - bg3.height / 2) > display.contentHeight) then
bg3.y = bg1.y - bg1.height;

elseif((bg4.y - bg4.height / 2) > display.contentHeight) then
bg4.y = bg1.y - bg1.height;

elseif((bg5.y - bg5.height / 2) > display.contentHeight) then
bg5.y = bg1.y - bg1.height;

elseif((bg6.y - bg6.height / 2) > display.contentHeight) then
bg6.y = bg1.y - bg1.height;

elseif((bg7.y - bg7.height / 2) > display.contentHeight) then
bg7.y = bg1.y - bg1.height;

end
end
[/code] [import]uid: 76800 topic_id: 24796 reply_id: 324796[/import]

You’re drawing bg2-8 all at the same place:

0, bg1.y + (bg1.height * 1.5)

Shouldn’t 3 be drawn at bg 2.y + (bg 2.height * 1.5)?

Also all of your relocate blocks are moving things to before bg1

Are your backgrounds the same size?
[import]uid: 19626 topic_id: 24796 reply_id: 100547[/import]

Thanks a lot, but now, the bg2 is looping to the infinite! Once again, here’s the code:

[code]
local bgSpeed = 2.5; – speed to move the backgrounds at

local bg1 = display.newImage(“backGround01.png”, 0, 0); – place bg1 at the origin
local bg2 = display.newImage(“backGround02.png”, 0, bg1.y + (bg1.height * 1.5)); – place bg2 right after bg1
local bg3 = display.newImage(“backGround03.png”, 0, bg2.y + (bg2.height * 1.5)); – place bg2 right after bg1
local bg4 = display.newImage(“backGround04.png”, 0, bg3.y + (bg3.height * 1.5)); – place bg2 right after bg1
local bg5 = display.newImage(“backGround05.png”, 0, bg4.y + (bg4.height * 1.5)); – place bg2 right after bg1
local bg6 = display.newImage(“backGround06.png”, 0, bg5.y + (bg5.height * 1.5)); – place bg2 right after bg1
local bg7 = display.newImage(“backGround07.png”, 0, bg6.y + (bg6.height * 1.5)); – place bg2 right after bg1

–bg1.x,bg2.x = 160,160
local moveBG = function(e)
bg1:translate(0, bgSpeed); – move bg1 bgSpeed on the y plane
bg2:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg3:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg4:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg5:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg6:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane
bg7:translate(0, bgSpeed); – move bg2 bgSpeed on the y plane

if ((bg1.y - bg1.height / 2) > display.contentHeight) then
bg1.y = bg2.y - bg2.height;

elseif((bg2.y - bg2.height / 2) > display.contentHeight) then
bg2.y = bg1.y - bg1.height;

elseif((bg3.y - bg3.height / 2) > display.contentHeight) then
bg3.y = bg2.y - bg2.height;

elseif((bg4.y - bg4.height / 2) > display.contentHeight) then
bg4.y = bg3.y - bg3.height;

elseif((bg5.y - bg5.height / 2) > display.contentHeight) then
bg5.y = bg4.y - bg4.height;

elseif((bg6.y - bg6.height / 2) > display.contentHeight) then
bg6.y = bg5.y - bg5.height;

elseif((bg7.y - bg7.height / 2) > display.contentHeight) then
bg7.y = bg6.y - bg6.height;
end
end
[/code] [import]uid: 76800 topic_id: 24796 reply_id: 100552[/import]