Continuously moving level

Hi, I am a newbie to corona and I have some basic questions. How do i design a level with physics bodies where the level continuously moves in the background(physics bodies and all ) while the character stays in the center of the screen (provided no physics body hits it)? And is it possible for a level to spawn outside the display screen, so that I may be able to implement a very long moving level? [import]uid: 64174 topic_id: 10670 reply_id: 310670[/import]

Here’s an example where the level moves while the player (the red circle) stays fixed to a position on the screen.

local physics = require( "physics" )  
physics.start()  
physics.setDrawMode( "hybrid" )  
  
local gameLayer = display.newGroup() -- master game group  
local ballGroup = display.newGroup()  
local levelObjects = display.newGroup()  
  
gameLayer:insert(levelObjects)  
gameLayer:insert(ballGroup)  
  
local myCircle = display.newCircle(ballGroup, 100, 100, 30 ); myCircle:setFillColor(128,0,0)  
physics.addBody( myCircle, { density=3.0, friction=0.5, bounce=0.3 } )  
  
local myRectangle = display.newRect(levelObjects, 0, 300, 480, 20); myRectangle:setFillColor(0,0,200)  
physics.addBody( myRectangle, "static", { density=3.0, friction=0.5, bounce=0.3 } )  
  
local myRectangle = display.newRect(levelObjects, 100, 280, 20, 20); myRectangle:setFillColor(0,0,200)  
physics.addBody( myRectangle, "static", { density=3.0, friction=0.5, bounce=0.3 } )  
  
local function moveLevel()  
 myCircle.x = myCircle.x + 1  
 gameLayer.x = -myCircle.x + 80  
end  
  
Runtime:addEventListener("enterFrame", moveLevel)  

I’ve only just started playing around with moving levels so I don’t completely understand how this works yet - it’s a little hard to wrap my head around, I’m used to working in engines that has a camera that you can move around, in corona you move the world around. Look at Ghosts vs. Monsters and EggBreaker for more examples of this (my example is basically the EggBreaker setup).

And yes it’s possible to make large levels that extend past the screen. Both of the Corona examples I mentioned are doing basically that. [import]uid: 48658 topic_id: 10670 reply_id: 38730[/import]

Thanks! [import]uid: 64174 topic_id: 10670 reply_id: 38746[/import]

Since the level’s movement is dependent on the ball’s movement, if the ball gets hung up on part of the level so that it’s stopped, then the level will stop too (or worse, maybe jitter and freak out?). It’s only a basic example, there are likely ways to do this better to avoid that situation. [import]uid: 48658 topic_id: 10670 reply_id: 38789[/import]

yes! did just a small change to the code…

[lua]local function moveLevel()
myCircle.x = myCircle.x + 1
gameLayer.x = gameLayer.x-1
end[/lua]

that should be enough for me… :slight_smile: [import]uid: 64174 topic_id: 10670 reply_id: 38799[/import]

Sorry to dig up this thread. But I have a Question. Is it necessary for the myCircle object to be part of the gameLayer? Can we just move the gameLayer behind and make the myCircle position constant? [import]uid: 64174 topic_id: 10670 reply_id: 48646[/import]