How to create a coin-based points display

5
  • 8 favourites

Stats

5,781 visits, 8,106 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Making a points display is infinitely easier than what you'd expect.

For this tutorial, we're going to learn how we can set points in a game. Like how many points earned, how many points you would earn, and how many points you can earn.

Using a points display can be used for nearly all genres of games, and all sorts of situations. Like how many enemies you killed in a shooter, how many coins you took in a platformer, or how many seconds you lasted in a survival game.

Today, we're going to learn about how many points would be earned from collecting coins in a game.

But first, we would need to make the calculations and display.

For this tutorial to work, you would need three objects. The object displaying the score(text object), the object collecting score(the player), and the object giving score(points UI; ex. coins).

The object that will display the score would need to be a text object. It can be a sprite text object as well, if you want.

The object collecting score would always be the player. You can give him controls of any kind, that's fine. But, you need a player.

The object that would give score, that would be a coin. So, with that being said, lets get to work.

So first off, lets go to the event sheet.

--------------------------------------------------------------------------------------------------------------------

Step 1

We would need a global variable. To place a global variable, right-click on the event sheet. Now, we need to personally create the global variable to best suit our needs. Be sure to make the variable's settings as of that below.

Name: Scoring

Type: Number

Initial Value: 0

Once that's done, press OK to confirm the variable.

--------------------------------------------------------------------------------------------------------------------

Step 2

Now since we're making a coin, we would say that this object would be "Coin".

Now, we need a player, so lets say that this object would be "Player".

And, we need a text object. Like I said before, it can be a normal Text Object, or a Sprite Text Object. Either would work the same way. But for now, we would say it would be named "Score".

Anyways, now that is out of the way, lets get back to the event sheet.

So to get points, we need the player to collect the points. So, we would make an event. This event would be like what's shown below.

"Player" On collision with "Coin"

Once that's done, we need to add some actions. So, we would need to make a system action.

Once we're in the Edit action menu, we would need for it to add points to our global variable. So, set it to Add to, found in "Global & local variables".

Next, we need to confirm how many points it'll give. First though, you would need to choose the variable it'll add to. Set the variable to "Scoring". If you're planning on 1 point, set the value 1. If you're planning on 2 points, set the value to 2. And, so on and so forth.

Once you've set the variable, your event should look like this.

"Player" On collision with "Coin": System: Add 1 to Scoring

--------------------------------------------------------------------------------------------------------------------

Step 3

Next off, we would need to make sure it displays the score for how many points you've earned.

So, lets go to the Text Object that we're using to display text.

We would need to create another action with our event. So, press Add action, and set the action to be made onto "Score".

Next, in the Edit action Menu, we would want to have to set the action to Set Text, found in "Text".

Now, we want the Text object to display our current score, so set the text to Scoring. It can't be just a number. If that happens, then it'll display the selected number, rather than our actual score. By setting it to Scoring, it'll have a direct link from the global variable. Once you've got that through, press Done.

Now, your event should look like this.

"Player" On collision with "Coin": System: Add 1 to Scoring

                                                           [i]Score: Set text to Scoring[/i]

--------------------------------------------------------------------------------------------------------------------

Step 4 (optional)

If you want the Coin to disappear after earning points, then just create another action on your current event.

Simply set the Coin to be destroyed after the player collected its score.

Your event should now look something like this:

"Player" On collision with "Coin": System: Add 1 to Scoring

                                                           [i]Score: Set text to Scoring[/i]
                                                           [i]Coin: Destroy[/i]

--------------------------------------------------------------------------------------------------------------------

Okay, what a mouthful. That's it, by the way. I'm learning more and more about this program, so just bear with me.

Any feedback can be accepted. If there's anything you have to say, please leave a comment.

-JGblkshot

  • 5 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • That's great and so well explained!

    I couldn't find anywhere, how can keep counting through the layouts, I mean, if first layout you ended with 20 coins, how to start the leyout 2 with these 20 coins...

    Thx!

  • this is good for Sea World

  • How to do in a shooting game... Here the player is to directly destroy the object but use a gun and bullet collide the object, so how to do this...

  • Why does the coin text not follow my character?