Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. Games

Quick Tip: A Simple Score Display for Flash Games

Read Time:6 minsLanguages:
This post is part of a series called Shoot-'Em-Up.
Build a Stage3D Shoot-'Em-Up: Explosions, Parallax, and Collisions
Build a Stage3D Shoot-'Em-Up: Terrain, Enemy AI, and Level Data

Almost all games out there use a scoring system to help players see their progress. It is essential to show the player’s score in a clear and fun way. In this Quick Tip we're going to learn how to do just that!


Click the button to add 20,000 points to your score:

In this Quick Tip we’re going to learn how to create a score display. To improve the quality of our display, we're going to do two things:

  1. Add commas to our score, so it reads 1,600,000 instead of 1600000. This makes it easier for the player to figure out how big his or her score is.
  2. Make our score transition between values, instead of changing immediately. This gives the player a sense of achievement, because he or she actually sees his score grow.

In the end we’ll have a very simple and useful class, which you can easily use within any of your projects.

This class will only concern itself with displaying the score, not with calculating it.

Step 1: Creating Our Class

First off let’s create our class; I’ve named it ScoreDisplay:

Step 2: Adding Our Score Variables

Let’s slowly add some variables:

We’re going to show our score in a TextField. If you’d like to use a Symbol when working with ScoreDisplay, you won’t need to create the text field by code. However, if you don’t want to use a Symbol, you’ll need to call createScoreField().

Do remember that if you want to use your own Symbol, you must give the text field inside that symbol the instance name of currentScoreField.

Step 3: Changing and Setting Our Score

Now let’s start thinking what we’d like to do with our ScoreDisplay class. We’d like to be able to set a score, as well as add or subtract from the player’s score. So let’s create those methods!

Step 4: Displaying Our Score

So far so good, we can now set and change the score’s value. But how will we display this? Even though it might not yet seem very useful, we’ll be using an enter frame event listener. Don’t worry it will make sense!

Step 5: Our Partly Finished Class

If we’d like to use our class in a project, it would look like this. Seems to work right - the score changes - but we aren't done. Remember what we wanted to do?

  1. Add commas to our score, so it reads 1,600,000 instead of 1600000.
  2. Make our score transition between values, instead of changing immediately.

Step 6: Adding Commas

Let’s start with the first goal, adding commas.

Step 7: Transitioning Between Scores

Now let’s work on our second goal; transitioning between score values, instead of changing to the new value immediately.

For this we can use the awesome capabilities of the Tween class. Most times we think of the Tween class for moving display objects, but you can use it to change any numerical value, including our score.

We're Done!

And that’s it! You could extends this class and maybe add some sounds or “fancy graphics”. I hope you had a great time and learnt something, cheers!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.