Hey Guys.
I am trying to create a vertical parallax background made out of 4 different 768 x 1024 backgrounds. I manage to make that. But each time a new background reappears on screen there is a small offset in the continuity and you can see the black background. I made a sample code so you can see what i am talking about so maybe you can help me.
If you can see in the code below the background will start to scroll down when the first background is off the screen with a new color background comes down. The thing is that there is a small offset and you can see the black background I want each color to be joint exactly at the bottom and the end so there is no offset.
Also is there a way to choose in a random way which color background will appear next on screen. Right now they appear on a certain order is it posible to do this in a random way
Any help will be appreciated thanks a lot.
display.setStatusBar(display.HiddenStatusBar)
local moveDown1 = 0
local moveDown2 = 0
local bg = display.newRect(0, 0, 768, 1024)
bg:setFillColor(0, 0, 0) --BLACK BG
local square = display.newRect(0, 0, 768, 1024)
square:setFillColor(0, 255, 150) --green
square.x = 384
square.y = 512
local square2 = display.newRect(0, 0, 768, 1024)
square2:setFillColor(250, 255, 0) --yellow
square2.x = 384
square2.y = -512
local square3 = display.newRect(0, 0, 768, 1024)
square3:setFillColor(255 ,100, 140) -- pink
square3.x = 384
square3.y = -512
local square4 = display.newRect(0, 0, 768, 1024)
square4:setFillColor(255 ,0, 0) -- red
square4.x = 384
square4.y = -512
local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
local yOffset = ( .4 * tDelta )
if moveDown1 == 0 then
square.y = square.y + yOffset
end
if moveDown2 == 0 then
square2.y = square2.y + yOffset
end
if moveDown1 == 1 then
square3.y = square3.y + yOffset
end
if moveDown2 == 1 then
square4.y = square4.y + yOffset
end
if square.y > 1536 then
square:translate( 0, -1024*2)
moveDown1 = 1
--moveDown1 = math.random(0,1)
end
if square2.y > 1536 then
moveDown2 = 1
square2:translate(0, -1024*2)
end
if square3.y > 1536 then
square3:translate(0, -1024*2)
moveDown1 = 0
--moveDown1 = math.random(0,1)
end
if square4.y > 1536 then
square4:translate(0, -1024*2)
moveDown2 = 0
--moveDown1 = math.random(0,1)
end
end
Runtime:addEventListener( "enterFrame", move )