Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Animating our Game > Time for action – starting the game

Time for action – starting the game

Time for action – starting the game Right now we need to set the off screen position for the panda and have it transition to its starting launch location so the user can interact with it. After adding the variables, create a new local function called startNewRound() and add an if statement to initiate the panda object into the scene. local startNewRound = function() if panda then Add a new local function called activateRound() within startNewRound(). Set the starting position of the panda display object on screen and add ground:toFront() so that ground appears in front of the panda character. local activateRound = function() waitingForNewRound = false if restartTimer then timer.cancel( restartTimer ) end ground:toFront() panda.x = 240; panda.y = 300; panda.rotation = 0 panda.isVisible = true panda.isBodyActive = true Create another local function called pandaLoaded(). Set gameIsActive = true and set the panda object's air and hit properties to false. Add panda:toFront() so that it appears in front of all the other game objects on screen and set the body type to "static". local pandaLoaded = function() gameIsActive = true panda.inAir = false panda.isHit = false panda:toFront() panda.bodyType = "static" end Transition the panda to y=225 in 1000 milliseconds. When the tween is completed, call the pandaLoaded() function using the onComplete command. Close the activateRound() function with end and call out to it. Close the if statement for panda and the startNewRound() function with end. transition.to( panda, { time=1000, y=225, onComplete=pandaLoaded } ) end activateRound() end end What just happened? When the level is activated, the panda is placed below the ground before it is visible to the player. For pandaLoaded(), the game is activated by gameIsActive = true and the panda is ready for launch by the player. The panda transitions from the ground level to an area on the screen where it can be accessed.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint