In this section, we'll fill the screen with our environment display objects. This includes our background and ground objects, and we can also add physical elements to our ground so that we can designate collision events for it. To draw the background, perform the following steps:
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