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 – tracking the score


The score updates through a parameter called scoreNum and displays it during the game play. The score number is received through gameScore.

  1. The next function that will be created is called setScore with a parameter called scoreNum:

    local setScore = function( scoreNum )
  2. Use a local variable called newScore and set it as scoreNum. Set the gameScore = newScore. Provide an if statement for gameScore, so that the score during game play is set to 0:

      local newScore = scoreNum
      gameScore = newScore
    
      if gameScore < 0 then gameScore = 0; end
  3. Add the scoreText display object and make it equal to gameScore. Close the function:

      scoreText.text = gameScore
      scoreText.xScale = 0.5; scoreText.yScale = 0.5
      scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
      scoreText.y = 20
    end

What just happened?

For setScore = function(scoreNum), we set a parameter called scoreNum. The scoreNum parameter will update the game score continuously through local newScore. newScore...