September 1, 2011
________________________________________________________________________
Games that show scores, number of lives left, items you collect, status, stats, etc... all of these games need parameters to be set up.
In Flash, it's very important to set parameters that you are using in your game at the beginning. As we can see in Figure 3.1, I just set my parameters in the second frame.
________________________________________________________________________
Games that show scores, number of lives left, items you collect, status, stats, etc... all of these games need parameters to be set up.
In Flash, it's very important to set parameters that you are using in your game at the beginning. As we can see in Figure 3.1, I just set my parameters in the second frame.
Figure 3.1
set_enemy = 3;
“set_enemy” is a parameter that I made it up.
“3” is what I set up for number of enemy in the game.
Another example we can look at is at line 24 and 25.
bg_x = 275;
bg_y = 190;
“bg_x” is a parameter that I will use for one of my backgrounds in x position.
“bg_y” is a parameter that I will use for one of my backgrounds in y position.
OK. That’s the basic to set your parameters at the beginning of the game. Now, let’s take a look at how we use it when we make a game. Figure 3.2 shows the background that I used in Stage 1 for Muay Thai 1. If I click at my background to select it, you can see the script on the Actions panel as the following.
Line 1: onClipEvent (enterFrame) {
Line 2: this._x = /:bg_x;
Line 3: this._y = /:bg_y;
Line 4: if (/:bg_x <= -275) {
Line 5: /:bg_x = 825;
Line 6: } else if (/:bg_x > 825) {
Line 7: /:bg_x = -265;
Line 8: }
Line 9: }
(My background is a movie clip behavior. There are 3 types of behavior in Flash, movie clip, button, and graphic)
Line 1, the “enterFrame” tells you that when the game runs through here, this script activates.
Line 2, “this._x” is the x position of my background (since I am selecting my background, I can use “this._x” where “this” refers to the thing that I select). I set it to the parameter of “bg_x”. Remember this “bg_x” we talked earlier above? (bg_x = 275; in Figure 3.2)
Do you see that I use “/:bg_x” instead of “bg_x” alone? It’s because whenever you refer to a parameter that you set value at the beginning, you have to put “ /: ” before the name of the parameter. Or you can use _root.bg_x instead.
Line 3, the same thing but for y position of my background.
Line 4 – 9 are just trying to make the background in boundary since this background will move according to the movement of the main character which I will talk about it later.
OK. I will show you how to refer your parameters. Look at Figure 3.3, you can see that I set x = 2, y =3, and z = 4 in the first frame at Scene 1.
Figure 3.3: I create a blue circle using “Oval Tool” and then I press F8,
name it as circle 1st level(movie clip type)
If I say,
m = x;
m = x;
n = y;
p = z;
Here, I will get
Here, I will get
m = 2
n = 3
p = 4
The blue circle is my movie clip named “circle 1st level”. Double clicking this blue circle will bring us inside its movie clip as seen in Figure 3.4.
The blue circle is my movie clip named “circle 1st level”. Double clicking this blue circle will bring us inside its movie clip as seen in Figure 3.4.
Figure 3.4
If I say
m = x;
n = y;
p = z;
I will get
m = 20
n = 30
p = 40
But if I say
m = ../:x;
n = ../:y;
p = ../:z;
I will also get
m = 2
n = 3
p = 4
One more time, if I say
m = /:x;
n = /:y;
p = /:z;
I will also get
m = 2
n = 3
p = 4
Now I select my blue circle again and press F8 to name it as “circle 2nd level”(movie clip type). Then I double click on this blue circle to get inside it again as seen in Figure 3.5.
Figure 3.5
If I say
m = x;
n = y;
p = z;
I will get
m = 200
n = 300
p = 400
But if I say
m = ../:x;
n = ../:y;
p = ../:z;
I will also get
m = 20
n = 30
p = 40
One more time, if I say
m = ../../:x;
n = ../../:y;
p = ../../:z;
I will get
m = 2
n = 3
p = 4
And here, if I say this
m = /:x;
n = /:y;
p = /:z;
I will also get
m = 2
n = 3
p = 4
For those of you who want to really see how to check for m, n, and p I was talking about, you can do as the followings.
First go deep inside your blue circle at “Circle 2nd level”.(see Figure 3.6)
Figure 3.7
m =
n =
p =
(see Figure 3.10)
Figure 3.10
Figure 3.11
Figure 3.13
Figure 3.14
Figure 3.15
Figure 3.17
x or /:x or../:x or ../../:x
in the “Var:” box for m and see what will happen.
(Note: You can set all parameter to be global(set parameters at scene 1) and use _global.x or _root.x to refer to the global parameters.)
Try it and see it on your own. I hope you get some idea about setting parameters.
No comments:
Post a Comment