Differences

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

Link to this comparison view

Both sides previous 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 [2018/09/13 23:39] (current)
4ian [Bonus: fixing the score bug]
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?​200 |}}
Line 174: Line 174:
 {{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose-4.png?​600 |}} {{ :​gdevelop5:​tutorials:​platform-game:​click-to-choose-4.png?​600 |}}
  
-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?​600 |}}
  
-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.+ 
 +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?​600 |}} {{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub1.png?​600 |}}
Line 188: Line 188:
 {{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub2.png?​600 |}} {{ :​gdevelop5:​tutorials:​platform-game:​move-to-sub2.png?​600 |}}
  
-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.+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.
  
 ## Next step: add enemies ## Next step: add enemies