In this section, we'll be filling the screen with our environment display objects. This includes our background and ground objects respectively and adding physical elements to our ground so that we can designate collision events for it.
Create a local function called
drawBackground()
.local drawBackground = function()
Add in the background image.
background = display.newImageRect( "bg.png", 480, 320 ) background.x = 240; background.y = 160 gameGroup:insert( background )
Add in the ground elements and create the ground physical boundary. Close the function.
ground = display.newImageRect( "grass.png", 480, 75 ) ground.x = 240; ground.y = 325 ground.myName = "ground" local groundShape = { -285,-18, 285,-18, 285,18, -285,18 } physics.addBody( ground, "static", { density=1.0, bounce=0, friction=0.5, shape=groundShape } ) gameGroup:insert( ground ) end