Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Created October 20, 2012 16:25
Show Gist options
  • Save shawngrimes/3923836 to your computer and use it in GitHub Desktop.
Save shawngrimes/3923836 to your computer and use it in GitHub Desktop.
Corona Scrolling Backgrounds Sample
--This is a work in progress
--Create the first background
local myBackground=display.newImage("background1.png")
myBackground:setReferencePoint(display.CenterLeftReferencePoint)
myBackground.x=0
--Create the second background
local myBackground2=display.newImage("background2.png")
myBackground2:setReferencePoint(display.CenterLeftReferencePoint)
myBackground2.x=display.contentWidth
--Function to move background1 to the leftmost point of the scene and then start to move background2 off the screen
moveBackground1=function(object)
myBackground.x=display.contentWidth
transition.to(myBackground,{time=3500,x=0})
transition.to(myBackground2,{time=3500,x=-myBackground2.contentWidth,onComplete=moveBackground2})
end
--Function to move background2 to the leftmost point of the scene and then start to move background1 off the screen
moveBackground2=function(object)
myBackground2.x=display.contentWidth
transition.to(myBackground,{time=3500,x=-myBackground.contentWidth})
transition.to(myBackground2,{time=3500,x=0,onComplete=moveBackground1})
end
--Start moving background2
moveBackground2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment