Problem with a simple scrolling bg

Hello guys I ve a big problem

I’m trying to create a bg that can be dragged.

local bg = display.newImageRect ("src/Labirinto1bg.jpg", 1140, 640) bg.x = display.contentCenterX bg.y = display.contentCenterY gruppo:insert(bg) local x local y function muovi(event) if event.phase == "began" then x = event.x y = event.y end if event.phase == "moved" then bg.y = (bg.y - y) + event.x bg.y = (bg.y - y) + event.y end end

But In this way my bg doesn’t move constantly but exponentially.

I can’t figure out how to fix it please help me

You’r problem is that you insert in the equation a 2 variables that change every time you drag your object. You should register what is the position of your bg when you are in the Began phase and use it to increase the bg position when you drag it.

local bg = display.newImageRect ("src/Labirinto1bg.jpg", 1140, 640) bg.x = display.contentCenterX bg.y = display.contentCenterY gruppo:insert(bg) function muovi(event) if event.phase == "began" then x = bg.x y = bg.y end if event.phase == "moved" then bg.y = x + (event.x - event.xStart) bg.y = y + (event.y - event.yStart) end end

It should work

You’r problem is that you insert in the equation a 2 variables that change every time you drag your object. You should register what is the position of your bg when you are in the Began phase and use it to increase the bg position when you drag it.

local bg = display.newImageRect ("src/Labirinto1bg.jpg", 1140, 640) bg.x = display.contentCenterX bg.y = display.contentCenterY gruppo:insert(bg) function muovi(event) if event.phase == "began" then x = bg.x y = bg.y end if event.phase == "moved" then bg.y = x + (event.x - event.xStart) bg.y = y + (event.y - event.yStart) end end

It should work