Featured Site
» Posted in the Flash Kit Links section
» Title: 3D Jobs
» Description: Free job forum for jobs in Films, Video Games, Multimedia and jobs in flash animation and scripting.
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);
}