Hi,
I have a scrolling background (right to left).
The background speeds up as the player moves towards the right.
I have a button that when pressed reverses the player.
When the button is cllicked I set a flag that tells the scrolling function to then move the background the opposite direction(left to right).
Problem is the background when reversed dosnt respond correctly to the speed and it dosnt scroll properly(missing images), I dont know how to stack the images the opposite way if you get my meaning.
Been messing with this for what seems like an age, so if anybody could take a quick it would be appreciated.
The flag is visible in the function.
So, bascially I need it to scroll right left (which it does) and speed up with player(which it does) But I need it do the same left to right please.
Thank you
[lua]
local terrain
local terrain1
_G.switchTerrain = 0
local function createWorld(layer)
local layer = layer or display.currentStage
--terrain = display.newRect(0,300,1000,1)
terrain = display.newImageRect(layer,“images/terrain.png”,1120,160,0,0)
terrain.x = 560
terrain.y = 150
terrain.anchorX = 0
terrain1 = display.newImageRect(layer,“images/terrain.png”,1120,160,0,0)
terrain1.x = 1680
terrain1.y = 150
terrain1.anchorX = 0
function updateTerrain()
--print(“player”,player.x)
print(switchTerrain)
terrain.x = terrain.x
terrain1.x = terrain1.x
if switchTerrain == 0 then
if player.x > 100 then terrain.x = terrain.x -1 end
if player.x > 150 then terrain.x = terrain.x -1.5 end
if player.x > 200 then terrain.x = terrain.x -2 end
if player.x > 250 then terrain.x = terrain.x -2.5 end
if player.x > 100 then terrain1.x = terrain1.x -1 end
if player.x > 150 then terrain1.x = terrain1.x -1.5 end
if player.x > 200 then terrain1.x = terrain1.x -2 end
if player.x > 250 then terrain1.x = terrain1.x -2.5 end
end
if switchTerrain == 1 then – had logic here as above to move the background faster with the player
terrain.x = terrain.x +3 – this is just a test but it runs but at about 1.5x
terrain1.x = terrain1.x +3 – EDIT
end
if (terrain.x + terrain.contentWidth) < 0 then
terrain:translate( 1120 * 2, 0)
end
if (terrain1.x + terrain1.contentWidth) < 0 then
terrain1:translate( 1120 * 2, 0)
end
end
Runtime:addEventListener(“enterFrame”,updateTerrain)
end
[/lua]
EDITed terrain -3 too +3 –