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 – starting physics for the paddle and ball


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:

  1. Above the gameLevel1() function, create a new function called startGame():

    function startGame()
  2. 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})
  3. Create an event listener that uses the background display object to remove the "tap" event for startGame(). Close the function with end:

      background:removeEventListener("tap", startGame)
    end
  4. In the addGameScreen() function that we created in the previous chapter, we have to add the following line after the call to the gameLevel1() function. This starts the actual game when the background is touched:

      background...