Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gdevelop5:tutorials:platformer:part-5 [2020/10/10 06:31]
davidturnbull
gdevelop5:tutorials:platformer:part-5 [2021/11/22 23:06] (current)
Line 1: Line 1:
 # Platformer Tutorial, Part 5: Add Collectible Coins to the Game # Platformer Tutorial, Part 5: Add Collectible Coins to the Game
  
-This part of the [Platformer Tutorial](#explains how to add collectible coins to the game.+This part of the tutorial explains how to add collectible coins to the game.
  
 You'll learn how to: You'll learn how to:
  
 - Delete an object (and play a sound) when a player collides with it. - Delete an object (and play a sound) when a player collides with it.
-- Keep track of data with [variables](#).+- Keep track of data with variables.
 - Add text to a scene. - Add text to a scene.
 +
 +## Series
 +
 +You are reading **Part 5** of the [[gdevelop5:tutorials:platformer:start|Platformer Tutorial]].
 +
 +1. [[gdevelop5:tutorials:platformer:start|Platformer Tutorial, Part 1]]
 +2. [[gdevelop5:tutorials:platformer:part-2|Platformer Tutorial, Part 2]]
 +3. [[gdevelop5:tutorials:platformer:part-3|Platformer Tutorial, Part 3]]
 +4. [[gdevelop5:tutorials:platformer:part-4|Platformer Tutorial, Part 4]]
 +5. Platformer Tutorial, Part 5
 +6. [[gdevelop5:tutorials:platformer:part-6|Platformer Tutorial, Part 6]]
 +7. [[gdevelop5:tutorials:platformer:part-7|Platformer Tutorial, Part 7]]
 +8. [[gdevelop5:tutorials:platformer:part-8|Platformer Tutorial, Part 8]]
 +
  
 ## Step 1: Create a collectible coin ## Step 1: Create a collectible coin
Line 19: Line 33:
 3. Drag one or more instances of the object into the scene. 3. Drag one or more instances of the object into the scene.
  
-**Note:** To duplicate a coin that's already in the scene, hold down the `CTRL` key (or `CMD` on macOS). Then select and drag an instance of the coin.+{{:gdevelop5:tutorials:platformer:05-01-coin-object.jpg|}} 
 + 
 +<note>To duplicate a coin that's already in the scene, hold down the `CTRL` key (or `CMD` on macOS). Then select and drag an instance of the coin.</note>
  
 ### Make the coin collectible ### Make the coin collectible
Line 27: Line 43:
 3. Add a **Delete an object** action to the event and configure the action to delete the "Coin" object. 3. Add a **Delete an object** action to the event and configure the action to delete the "Coin" object.
 4. Add a **Play a sound** action to the event that plays a sound effect when the player collects a coin. (You can use the "coin.wav" asset for the sound effect.) 4. Add a **Play a sound** action to the event that plays a sound effect when the player collects a coin. (You can use the "coin.wav" asset for the sound effect.)
 +
 +{{:gdevelop5:tutorials:platformer:05-02-coin-collectible.jpg|}}
  
 If you preview the game, colliding with a coin deletes the coin and plays a sound. If you preview the game, colliding with a coin deletes the coin and plays a sound.
 +
 +{{:gdevelop5:tutorials:platformer:05-02-collect-coin-preview.gif|}}
  
 ## Step 2: Keep track of the collected coins ## Step 2: Keep track of the collected coins
  
-Every time a user collects a coin, the game needs to keep track of the number of coins the player has collected. To do this, the game needs a *variable*.+Every time a user collects a coin, the game needs to keep track of the number of coins the player has collected. To do this, the game needs a [[gdevelop5:all-features:variables|variable]].
  
 A variable is a container that can store data. If you've ever done algebra, then you're familiar with variables, as letters like "x" and "y" are often used as variables. A variable is a container that can store data. If you've ever done algebra, then you're familiar with variables, as letters like "x" and "y" are often used as variables.
Line 51: Line 71:
 4. In the **Value** field, type "1" (without the double quotes). 4. In the **Value** field, type "1" (without the double quotes).
 5. Click **OK**. 5. Click **OK**.
 +
 +{{:gdevelop5:tutorials:platformer:05-03-scene-variable.jpg|}}
  
 This keeps track of the number of coins collected by the player, but this number doesn't (yet) appear on the screen. This keeps track of the number of coins collected by the player, but this number doesn't (yet) appear on the screen.
Line 64: Line 86:
 3. Click **Apply**. 3. Click **Apply**.
 4. Drag an instance of the object into the scene. 4. Drag an instance of the object into the scene.
 +
 +{{:gdevelop5:tutorials:platformer:05-04-text-object.jpg|}}
  
 ### Update the "Score" object with the number of collected coins ### Update the "Score" object with the number of collected coins
  
-Before you can update the rendered text with the number of collected coins, it's important to have a broad understanding of *expressions*.+Before you can update the rendered text with the number of collected coins, it's important to have a broad understanding of [[gdevelop5:expressions|expressions]].
  
 In GDevelop, expressions are similar to spreadsheet formulas or functions in a programming language. You can pass a value into an expression and receive a value. In GDevelop, expressions are similar to spreadsheet formulas or functions in a programming language. You can pass a value into an expression and receive a value.
Line 92: Line 116:
 4. In the **Value** field, type `"Score: " + ToString(Variable(Score))`. This value uses the `ToString` and `Variable` expressions to convert the number of collected coins into a string. It also uses the `+` operator to combine two strings into a single string. 4. In the **Value** field, type `"Score: " + ToString(Variable(Score))`. This value uses the `ToString` and `Variable` expressions to convert the number of collected coins into a string. It also uses the `+` operator to combine two strings into a single string.
 5. Click **OK**. 5. Click **OK**.
 +
 +{{:gdevelop5:tutorials:platformer:05-05-modify-text-object.jpg|}}
  
 If you preview the game, the number of collected coins appears on the screen. If you preview the game, the number of collected coins appears on the screen.
 +
 +{{:gdevelop5:tutorials:platformer:05-06-score-preview.gif|}}
 +
 +<note tip>You can find more //expressions// in the //expression editor// by clicking on the blue icon next to the value fields:
 +
 +{{ :gdevelop5:tutorials:platform-game:expression-icon.png?nolink |}}
 +
 +When you click the blue icon, you can search all the available expressions sorted into categories.
 +
 +{{ :gdevelop5:tutorials:platform-game:expression-editor.png?nolink |}}
 +</note>
  
 ### Move the text to a different layer ### Move the text to a different layer
  
-There's a problem with the "Score" object: if you preview the game, the object remains in a fixed position. This means, if the player moves too far from the starting point, the number of collected coins is no longer visible.+There's a problem with the "Score" object: the number of collected coins is only visible if the player is standing in certain positions.
  
 To fix this, move the "Score" object to a different layer: To fix this, move the "Score" object to a different layer:
Line 107: Line 144:
 5. From the **Layer** dropdown, select "UI". 5. From the **Layer** dropdown, select "UI".
  
-## (Optional) Step 4Handle overlapping coins+{{:gdevelop5:tutorials:platformer:05-07-change-layer.gif|}} 
 + 
 +If you preview the game, the score remains in a fixed position.
  
-There's something wrong with the coins.+{{:gdevelop5:tutorials:platformer:05-08-score-ui-layer-preview.gif|}}
  
 ## Next step ## Next step
  
-Read [Platformer Tutorial, Part 6](#).+Read [[gdevelop5:tutorials:platformer:part-6|Platformer Tutorial, Part 6]].