» Home » Movies » Tutorials » Submissions » Sound FX » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops
Search tutorials
Author: Mirza Hatipovic

## Gaming: coding the skala of remaining lives

This tutorial shows how to implement one of most basic features in game development: the skala in the upper left corner displaying the number of remaining tries(lives). The advantage of this snippet is that you can use it over and over in your flash games. You only have to change this symbol in library that represents a «life» in your game. We will use the attachMovie method to place it on the stage. Now, first of all, create a movieclip in your library. The dimension should be appr. 30x30 px. Now export this symbol with the identifier «life». That's the first step. You don't have to place the symbol on the stage manually, the attachMovie method will do it for you. Now let's do some coding: First of all, we will have to set a cnstant. This constant will contain the value of max. lifes that you allow per game. Remember that you can change the value. So the first line of code should be:
```MAX_LIVES = tries_remain = 5;
```
This means that we will have max. Five tries per game. Next, we need a for loop to place the symbols on the stage. In our example, the loop will place 5 symbols on the stage.
```//initial x position on stage, should not be altered
init_x_dist = 20;

//y position of the mc's
y_pos = 20;

//distance between the mcs
distance_step = 30;

//the distance between the mc's on the stage

//place the symbols on the stage
for (i = 1; i <= tries_remain; i++) {
_root.attachMovie("life", "life" + i, i);
_root["life" + i]._y = y_pos;
_root["life" + i]._x = (i == 1 ? init_x_dist : init_x_dist += distance_step);
}
```
 » Level Advanced Added: 2003-04-03 Rating: 6 Votes: 15 1 2 3 4 5 6 7 8 9 10 (10 being the highest) » Author Mirza Hatipovic is freelance developer based in Bosnia and Hercegowina. He uses Flash, PHP and related tools to create dynamic web content. » Download Download the files used in this tutorial. Download (2 kb) » Forums More help? Search our boards for quick answers!

• There are no comments yet. Be the first to comment!

• You must have javascript enabled in order to post comments.

Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.