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

Platformer Tutorial, Part 5: Add Collectible Coins to the Game

Prerequisites

Before starting this tutorial, read Platformer Tutorial, Part 4. You also need to download the required assets. (If you downloaded the assets in a previous tutorial, you're good to go.)

Create a collectible coin

  1. Create an object named “Coin”.
  2. Create a new event.
  3. Add a Collision condition to the event that checks if the “Player” object has collided with the “Coin” object.
  4. Add a Delete an object action to the event that deletes the “Coin” object.
  5. Add a Play a sound action to the event that plays a sound effect when the player collects a coin.

Display the number of collected coins

  1. Add a Value of a scene variable action to the event.

Step 1: Create an object for the coin

  1. Open the Scene editor.
  2. In the Objects panel, click Add a new object.
  3. Select Sprite.
  4. In the Object name field, type “Coin”.
  5. Click Add an animation.
  6. Click Add.
  7. When the file chooser opens, select the “coinGold.png” asset.
  8. Click Apply.

Then drag some instances of the coin into the scene.

Step 2: Make the coins collectible

Detect when the player collides with a coin

  1. Open the Events editor.
  2. Click Add a new event.
  3. Click Add a condition.
  4. Select the “Player” object.
  5. From the list of conditions, select Collision.
  6. Select the “Coin” object.
  7. Click OK.

Delete the collected coin

  1. Click Add action.
  2. Select the “Coin” object.
  3. From the list of actions, select Delete an object.
  4. Click OK.

Play a sound when collecting a coin

  1. For the same collision condition, click Add action.
  2. Click Other actions.
  3. Expand Audio.
  4. Select Play a sound.
  5. Click Choose a new audio file.
  6. When the file chooser opens, select the “coin.wav” asset.
  7. Click OK.

Step 3: Display the number of collected coins

Create a variable to keep track of the score

  1. For the same collision condition, click Add action.
  2. Click Other actions.
  3. Expand Variables.
  4. Select Value of a scene variable.
  5. In the Variable field, type “Score”.
  6. From the Modification's sign dropdown, select + (add).
  7. In the Value field, type “100”.
  8. Click OK.

<!– 5. Click the icon alongside the Variable field. 6. Click Add. 7. Replace the default name of the variable with “Score”. 8. Provide a default value of “0” for the variable. 9. Click Apply. –

>

### Create a text object to display the score

  1. Open the Scene editor.
  2. In the Objects panel, click Add a new object.
  3. Select Text.
  4. In the Object name field, type “Score”.
  5. In the Initial text to display field, type “Score:”.
  6. Click Apply.
  7. Drag an instance of the object into the scene.