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 – displaying the game over screen

Time for action – displaying the game over screen

Time for action – displaying the game over screen We need to set up the game over screen and have it display the final score the player has achieved at the end of the round. Create a new local function called callGameOver(). local callGameOver = function() Set gameIsActive = false and pause the physics engine. Remove the panda and stars objects from the stage. gameIsActive = false physics.pause() panda:removeSelf() panda = nil stars:removeSelf() stars = nil Display the game over objects and insert them into the hudGroup group. Use the transition.to method to display the game over objects on screen. local shade = display.newRect( 0, 0, 480, 320 ) shade:setFillColor( 0, 0, 0, 255 ) shade.alpha = 0 gameOverDisplay = display.newImage( "gameOverScreen.png") gameOverDisplay.x = 240; gameOverDisplay.y = 160 gameOverDisplay.alpha = 0 hudGroup:insert( shade ) hudGroup:insert( gameOverDisplay ) transition.to( shade, { time=200, alpha=0.65 } ) transition.to( gameOverDisplay, { time=500, alpha=1 } ) Update the final score with a local variable called newScore. Set isVisible = false for the counter and scoreText. Introduce the scoreText again to display the final score in a different location on the device screen. Close the function. local newScore = gameScore setScore( newScore ) counter.isVisible = false scoreText.isVisible = false scoreText.text = "Score: " .. gameScore scoreText.xScale = 0.5; scoreText.yScale = 0.5 scoreText.x = 280 scoreText.y = 160 scoreText:toFront() timer.performWithDelay( 1000, function() scoreText.isVisible = true; end, 1 ) end What just happened? callGameOver() displays the game over screen when time runs out or if all the stars are collected. We set gameIsActive = false and paused all the physics so the panda cannot be moved with any other screen touches. The panda and stars are then removed from the scene. shade and gameOverDisplay are visible through transition.to so it notifies the player that the round is over. The final score will display at the end of the round in front of the gameOverDisplay object.

  

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