So you need two copies of the image you want to scroll. The image needs to be wide enough to cover the entire screen, not your content area. So if your config.lua width is 768 and you’re on a 16:9 phone, your background image width needs to be 1366 x 768. If you concern yourself with the Galaxy S8 you need a 2:1 aspect ratio background ( 1536 x 768) and if you’re going to deploy to iOS and the iPhone X is a 19.5:9 aspect ratio or 1665 x 768. Of course, these wider images will work on narrower screens.
Load two copies into memory:
local background1 local background2 local function moveBackground() background1.x = background1.x - 1 -- or whatever speed you want background2,x = background2.x - 1 if ( background1.x \< -background1.contentWidth + display.safeScreenOriginX ) then background1.x = background2.width + display.safeScreenOriginX end if ( background2.x \< -background2.contentWidth + display.safeScreenOriginX ) then background2.x = background1.width + display.safeScreenOriginX end end -- somewhere in scene:create() if you're using Composer: background1 = display.newImageRect("background.png", 1665, 768) sceneGroup:insert( background1 ) background1.x = display.safeScreenOriginX background1.y = display.contentCenterY -- assuming you want it centered background2 = display.newImageRect("background.png", 1665, 768) sceneGroup:insert( background2 ) background2.x = background1.x + background2.width \* 0.5 -- this should put it off screen to the right background2.y = display.contentCenterY -- assuming you want it centered -- somewhere in scene:show()'s "did" phase: Runtime:addEventListener("enterframe", moveBackground)
Now I made this code up, but it should get you close. This does not compensate for delta time, that is that enter frame doesn’t fire off exactly ever 1/x frames. You can make minor adjustments to let you smooth out the animation. Others may chime in with the code or you can search for the delta time tutorials and forum posts. This also assumes you will be supporting an iPhone X. (Actually now that I think about it, you probably won’t use safeZone insets for the background on the iPhone X for backgrounds…) So you can probably get away with just using display.screenOriginX.
Rob