In general you need two things:
-
a variable to hold the numeric value of the score. This is something you can do math with.
-
a display.newText() object that you can show the score in.
Increment the score any way you choose. After you increment it, update the text object with the new value.
Now there are a few gotcha’s. First, if you’re using multiple scenes with something like Composer or Storyboard, you need a way to pass that score around (and potentially the text object, though generally that just shows on the game screen, you may want to have other display.newText’s on your game over, high score screens etc.
The easy thing to do is make score a global, but that’s bad practice. It’s best to have a table that you require in every scene that has your variables you want to pass around every where.
Finally you may want to have a way to save the high score out so that the next time the app runs, you can remember what the previous high score was.
These concepts are pretty simple:
score = score + someAmount
scoreText.text = score
Of course you have to create the scoreText, position it, etc. and make sure it’s available when you want to change your score. That tutorial tries to do a lot of this for you.
Rob