To start with, any help at all with this is greatly appreciated. I have a level map picture that can be scrolled from left to right and match up. I would like to make it so that the user can scroll between this background level map using touch and all the objects layered on top of the level map will also scroll with it. There are 10 levels per a picture and 100 levels in the game, the user should only be able to scroll 10 levels in front of the current level. So if on level 55 the user should only be able to scroll from levels 1 to 65 (56 - 65 will show locked pictures). Lastly when the screen loads the current level should be in the center of the screen so user does not have to scroll to it every time.
I am sure someone has asked this before, maybe someone can help point me to the right post. Everytime I look all I find is endless scrollers that scroll on there own.
As of now all the code is trying to do is make the background scrollable. If I can manage this then im pretty sure I can do all the other stuff on my own (current level in the middle etc… although im not positive how to make objects layered on top scroll with it).
-- Set Variables for Device Width and Height local deviceWidth = display.contentWidth local deviceHeight = display.contentHeight -- Hide status bar display.setStatusBar( display.HiddenStatusBar ) --Create Amount Of Backgrounds Based On Level You Are On (Should Be One Ahead Below But Its Not Because For Loop In Create Backgrounds Underneath Will Go To 0 Instead Of 1) local backgroundTable = {} local howManyBG local testLevel = 32 local testLeveDiv = testLevel/10 local testLevelDec = testLevel%10 if testLevelDec \< 5 then howManyBG = math.round(testLeveDiv) else howManyBG = math.round(testLeveDiv)-1 end --Create Backgrounds for x=howManyBG,0,-1 do local background = display.newImageRect( "easyMap.png", deviceWidth, deviceHeight ) background.x = display.contentCenterX+(deviceWidth\*x) background.y = display.contentCenterY background.num=x table.insert(backgroundTable,background) end --Scroll Function local function moveBG( event ) local backgroundEvent = event.target local phase = event.phase if ( "began" == phase ) then display.currentStage:setFocus( backgroundEvent ) backgroundEvent.touchOffsetX = event.x - backgroundEvent.x for y=#backgroundTable,1,-1 do if backgroundTable[y].num ~= backgroundEvent.num then if backgroundTable[y].num \> backgroundEvent.num then backgroundTable[y].touchOffsetX = (event.x+(y\*deviceWidth)) - backgroundEvent.x elseif backgroundTable[y].num \< backgroundEvent.num then backgroundTable[y].touchOffsetX = (event.x-(y\*deviceWidth)) - backgroundEvent.x end end end elseif ( "moved" == phase ) then if backgroundTable[#backgroundTable].x \< 1+display.contentCenterX then for y=#backgroundTable,1,-1 do if backgroundTable[y].num ~= backgroundEvent.num then if backgroundTable[y].num \> backgroundEvent.num then backgroundTable[y].x = (event.x+(y\*deviceWidth)) - backgroundEvent.touchOffsetX elseif backgroundTable[y].num \< backgroundEvent.num then backgroundTable[y].x = (event.x-(y\*deviceWidth)) - backgroundEvent.touchOffsetX end end end backgroundEvent.x = event.x - backgroundEvent.touchOffsetX end elseif ( "ended" == phase or "cancelled" == phase ) then if backgroundTable[#backgroundTable].x \> 1+display.contentCenterX then for x=howManyBG,0,-1 do backgroundTable[x+1].x = display.contentCenterX+(deviceWidth\*x) end end display.currentStage:setFocus( nil ) end return true end --Create Background Event Listeners for z=#backgroundTable,1,-1 do backgroundTable[z]:addEventListener( "touch", moveBG ) end