Hello! Today’s post is going to be shorter than usual, but it’s a vital part of developing our game with Corona SDK! If you would like to see the previous post on this topic, please visit the Corona SDK tutorials menu item or go to the previous post here.
In the previous post, we covered how to add a coin to the screen and how to make the player ‘grab’ the coin. Today, we are going to track how many times the player caught a coin by adding a simple scoring system to the game. We do this by setting up a score variable to track the number of scores and we set up a text display object to show the player the score. Here’s the code.
-- On line 15, add the variable score score = 0; -- Set Score to 0 -- On line 63 to 65, add the following lines -- Add Score to Screen local playerScore = display.newText("Score: "..score, 0, 0, native.systemFont, 16); playerScore:setTextColor(0, 0, 0);
Next, we will add the scoring functionality. Everytime the player collides with the coin, we want to add 1 point to the score variable and update the text display object with the latest score. Here’s how.
-- Add the following to Line 122 score = score + 1; playerScore.text = "Score: " .. score
And that’s it! We’ve added a simple scoring system to our game. If you would like to see more tutorials, please leave a comment. This helps keep me motivated to continue to bring high quality tutorials to your site. As always, you can download the full source below. As always, you can download the full source below.