The score updates through a parameter called scoreNum
and displays it during the game play. The score number is received through gameScore
.
The next function that will be created is called
setScore
with a parameter calledscoreNum
:local setScore = function( scoreNum )
Use a local variable called
newScore
and set it asscoreNum
. Set thegameScore = newScore
. Provide anif
statement forgameScore
, so that the score during game play is set to 0:local newScore = scoreNum gameScore = newScore if gameScore < 0 then gameScore = 0; end
Add the
scoreText
display object and make it equal togameScore
. 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