Right now, our display objects are rather stagnant. In order for the game play to initiate, we have to activate physics for collision detection to occur between the paddle and ball. Perform the following steps:
Above the
gameLevel1()
function, create a new function calledstartGame()
:function startGame()
Add in the following lines to instantiate the physics for 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...