You can have three display groups (usually placed within a parent display group, for convenience) and move them left/right by adjusting their .x value relative to the user’s touch (if dragging is how the user moves the level.)
Here is some simple code to do the parallax scrolling:
[lua]-- scene is used here because I took this from my storyboard code, but it could be any table…
scene.backratio = 0.9 – difference between the interaction layer and the background motion
scene.foreratio = 0.4 – difference between the interaction layer and the foreground motion
– create the display groups and set opacities
local container = display.newGroup(); scene.container = container
local back, interact, fore = display.newGroup(), display.newGroup(), display.newGroup()
container:insert(back); container:insert(interact); container:insert(fore)
back.alpha = 1; interact.alpha = 1; fore.alpha = 0.4
– create the touch event used to move the display groups
– this uses the ratios created above to move them in a parallax style - out of sync of the user’s touch
local function touch( event )
if (event.phase == “began”) then
else
local x, y = 0, event.y-scene.event.y
back.x, back.y = back.x+scene.backratio*x, back.y+scene.backratio*y
fore.x, fore.y = fore.x+scene.foreratio*x, fore.y+scene.foreratio*y
end
scene.event = event
end
scene.touch = touch
Runtime:addEventListener( “touch”, scene.touch )[/lua]
Please bear in mind that the code above is directly from my code and actually moves the display groups up and down. I will leave it as a task for you to modify the code to move left and right. Hint: You only need to change the line which has "local x, y = " to do this. [import]uid: 8271 topic_id: 29554 reply_id: 118616[/import]