Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)