Featured FLA
» Author: Sphere
» Title: Reacting Waves
» Description: Small red waves on a plane react when the mouse pointer nears them.
» More by Sphere
BBM.net is designed to save you time and deliver the highest quality royalty-free music for your multimedia projects. Features include: over 450 Music Loop Packages from some of the best composers in the business, our music search engine to speed your selection process, alternate music versions & bonus sounds to use for rollovers or transitions, free technical support and free consulting.
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);
}