Book Image

Learning Construct 2

By : Aryadi Subagio
Book Image

Learning Construct 2

By: Aryadi Subagio

Overview of this book

Table of Contents (17 chapters)
Learning Construct 2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding collectibles


Collectibles are coins or other objects that the players can collect in the game. These collectibles often add something like scores or game coins. In our game, the collectibles will also be randomized. First, create a new star game object with a sprite from starGold in the Tappy Plane folder and put it in the Collectibles layer. Give it a Bullet behavior and put it outside the screen.

We will create new collectibles every few seconds instead of making them every time the game creates a ground object, like the rock obstacles object. To make collectibles, write the following code:

We also want to show what these collectibles collect. So, let's create a new text object; name it scores and put it in the HUD layer. Put it in the upper-left part of the screen; this is where HUDs usually are, although they can be in a variety of places. Now, when the player collects the collectibles, we want the collectibles to be destroyed and then add the score. So, create a global variable...