Coin Collect Example
by grazer
Item Collecting
This recipe explains how to add collectable items to your game.
Create the item
First create a new object that will be our new collectable item. In our example we used a coin,
which we will use to increment a score counter.
Item
Trigger when touched
When the player touches the item, remove it from the game
Add a new Collision trigger, and set it to the type
of your player object. This way, the trigger will fire
when the player contacts it.
(Optionally) Play a sound
When the player collects an item, play a sound
Add a sound behavior
Add a new Sound behavior, and select a sound to play.
A custom sound can be played instead by adding an .mp3
URL.
If using a URL:
Make sure it ends with ".mp3"
When the play input is connected to the Collision
trigger's hit output, the selected sound will play when
the player touches the item.
Remove the item
Add a new Destroyer behavior. When connected to the output of
the Sound behavior, this will remove the item object from the
game when the sound plays.
Player
Update the Player's Score
Keep track of collected items
Trigger when touching the item
When the player touches the item, increment the score.
Add a new Collision trigger, and set it to the type
of your item object. This way, the trigger will fire
when the player contacts it.
Track the Score
Add a new Number behavior to store the score. Connect the hit output
of the Collision trigger to the + input of the Number behavior. This
will increment the number each time the Player touches the collectable item.
Display the New Score
Add a new Label behavior to display the score. Connect the output
of the Number trigger to the value input of the Label behavior.
This will display the newly updated score value on the screen.