Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – adding game listeners


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:

  1. The last function we need to create in order to complete this game is called gameListeners(), which will also have a parameter called event. This should be added right after the gameLevel2() function:

    function gameListeners(event)
  2. 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)
  3. Next, we'll add in an elseif statement for the event listeners that will remove the events and then close the...