**This is an old revision of the document!**

Add coins and display the number of collected coins

This tutorial is part of the How to make a platform game tutorial, but you can also re-use it for any other game where you can collect items!

In the platformer game we've created so far, the player has nothing much to do: let's add coins for the player to collect.

Add coins

Start by creating a new Sprite object with an animation with the coinGold image:

You can name this object “Coin”. You can then put several coins in the level. As you'll need several coins, it's a good idea to use the “drag and clone” feature of the scene editor: select a coin, keep pressing Ctrl (or Cmd on macOS), and drag the coin. This will duplicate it.

If you hold Shift while moving, you'll also be able to move the coin created on the same axis that the original one.

Delete coins when collected

Now, let's destroy the coin object when the player touch them. Add a new event and add a condition. Choose the condition to test for a collision between two objects. The first object should be Player and the second object should be Coin:

You can then add an action that will delete the coin. Only Coin objects that are picked by the first condition will be used by the action, so only the coin that was colliding with the player will be deleted.

Add an action “Delete an object” (in category Common actions for all objects > Objects) and enter Coin as the object to be deleted:

The event should look like this:

You can now launch a preview and see that coin are deleted when the player run on them!

Play a sound when collecting a coin

Display and increase a score using variables

We're going to use a variable to update and remember the score of the player. Variable are useful to remember all kind of information. There are scene variables (the most used ones), global variables (variables that are shared between all scenes of the game) and objects variables (which are specific to each instance of an object. There are also very useful and we'll use one for creating an enemy later).

The variable we're going to use will be called “Score”.

Add an action in the latest event we've made. Choose action Variables > Value of a variable. This action will be used to add 100 to the Score variable, so fill the parameter as shown here: