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:platform-game:5-add-coins-and-number-of-collected-coins [2018/09/12 21:15]
4ian
gdevelop5:tutorials:platform-game:5-add-coins-and-number-of-collected-coins [2019/12/27 10:50] (current)
4ian [Bonus: making sure that collecting two coins at the same time works]
Line 158: Line 158:
 {{ :​gdevelop5:​tutorials:​platform-game:​screen_shot_2017-09-30_at_19.00.24.png?​nolink |}} {{ :​gdevelop5:​tutorials:​platform-game:​screen_shot_2017-09-30_at_19.00.24.png?​nolink |}}
  
-## Bonus: ​fixing ​the score bug+## Bonus: ​making sure that collecting two coins at the same time works
  
-You might have noticed that if you collect two coins at the same time, the score only counts ​once. For example, if each coin is worth 100 points and you collect 2 coins, the score will only go up to 100 instead of 200. The fix for this is easy and is something we haven'​t looked at yet: an event called For Each Object. What we will do is tell the engine that for every single coin, add 100 to the score.+You might have noticed that if you collect two coins at the exact same time (for example, if two coins overlap), the score is only increased ​once. For example, if each coin is worth 100 points and you collect 2 coins, the score will only go up to 100 instead of 200. The fix for this is easy and is something we haven'​t looked at yet: we're going to use an event called For Each Object. What we will do is tell the engine that for every single coin that was collected, add 100 to the score.
  
-To start, click the + button in the toolbar:+To start, click the + button in the toolbar ​of the Events Editor:
  
-{{ :​gdevelop5:​tutorials:​platform-game:​gdevelop_5_2018-05-30_11-30-39.png?200 |}}+{{ :​gdevelop5:​tutorials:​platform-game:​gdevelop_5_2018-05-30_11-30-39.png |}}
  
 Select "for each object":​ Select "for each object":​
  
-{{ :​gdevelop5:​tutorials:​platform-game:​2018-05-30_11-33-09.png?400 |}}+{{ :​gdevelop5:​tutorials:​platform-game:​2018-05-30_11-33-09.png |}}
  
 This will add an event at the bottom of the event page. Drag it up and make it a sub-event of the player collision with the coin:  This will add an event at the bottom of the event page. Drag it up and make it a sub-event of the player collision with the coin: 
  
-{{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose-4.png?600 |}}+{{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose-4.png |}}
  
-Click to choose an object+Click to choose an object, and choose ​the Coin object.
-Type coin in the field that appears, and click on the object.+
  
-{{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose2.png?600 |}}+{{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose2.png |}}
  
-Now that you've added the object to the sub-event, let's move the actions down to the sub-event.  +Now that you've added the object to the sub-event, let's move the actions down to the sub-event ​(so that the actions will be repeated ​for each coin that is picked by conditions)
-Hover over the first action, right-click and cut it, then hover over the action in the sub-event, right-click,​ and paste. do this for each of other two actions.+
  
-{{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub1.png?600 |}}+Hover over the first action, right-click and cut it, then hover over the action in the sub-event, right-click,​ and paste. Do this for the other two actions. You can also drag'​n'​drop actions, which is faster than cut-pasting them. 
 + 
 +{{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub1.png |}}
  
 This is what the final event should look like:  This is what the final event should look like: 
  
-{{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub2.png?600 |}}+{{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub2.png |}} 
 + 
 +Now run the game, and you will see that if you gather two coins at the same time, the score will be updated properly if you run on two coins at the exact same time. 
 + 
 +<​note>​You can check the proper working of this by putting two coins at the same position in the scene.</​note>​
  
-Now run the game, and you will see if you gather two coins at the same time, the score will update to reflect that you indeed collected two coins, rather than one. 
  
 ## Next step: add enemies ## Next step: add enemies