Right now, our display objects are rather stagnant. In order for gameplay to initiate, we have to activate physics for the paddle and ball in order for any kind of movement in the game to occur.
Above the
gameLevel1()
function, create a new function calledstartGame()
.function startGame()
Add in the following lines to instantiate the physics of the paddle and ball:
physics.addBody(paddle, "static", {density = 1, friction = 0, bounce = 0}) physics.addBody(ball, "dynamic", {density = 1, friction = 0, bounce = 0})
Create an event listener that uses the background display object to remove the
"tap"
event forstartGame()
. Close the function withend
.background:removeEventListener("tap", startGame) end
In the
addGameScreen()
function that we created in the previous chapter, we have to add the following line after the call to thegameLevel1()
function. This starts the actual game when the background is touched.background:addEventListener...