For many of the functions we have created for our game objects, we need to activate the event listeners so that they will run the code and then disable them when game play has stopped. To add game listeners, follow these steps:
The last function we need to create in order to complete this game is called
gameListeners()
, which will also have a parameter calledevent
. This should be added right after thegameLevel2()
function:function gameListeners(event)
Add in the following event listeners that will start several events in the application, using an
if
statement:if event == "add" then Runtime:addEventListener("accelerometer", movePaddle) Runtime:addEventListener("enterFrame", updateBall) paddle:addEventListener("collision", bounce) ball:addEventListener("collision", removeBrick) paddle:addEventListener("touch", dragPaddle)
Next, we'll add in an
elseif
statement for the event listeners that will remove the events and then close the...