Parameters

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.

Clipboard01



































 Figure 3.1
 
As you can see there are a lot of parameters in Actions panel. At the beginning of my game making, I don’t have this many parameters. It was just added up along the way when I keep making my game until it is done. For example, if you look at the Actions panel, line 1, you will see…
   
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)
    
Figure 3.2
    
Let’s see what is going on on the script line by line.
   
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.
  
Clipboard06
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;
n = y;
p = z;
   
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.
   
Clipboard07
Figure 3.4
  
In here, I set x = 20, y = 30, and z = 40 at the beginning of frame 1.
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.
  

Clipboard08
Figure 3.5
  
In here, I set parameters x = 200, y = 300, and z = 400 at the first frame as seen in the Figure.
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)
  
Clipboard20 Figure 3.6
  
Use the Text tool as shown in Figure 3.7 below.
  
Clipboard09 
Figure 3.7
  
Place your text like so. But hold on! Before you put any word in the text box, look at the properties tab down below(or press Ctrl + F3).(see Figure 3.8)
  
Clipboard10 Figure 3.8
  
You will see a dropdown menu for text type. Change it to “Static Text” as in Figure 3.9.
  
Clipboard11 Figure 3.9
  
Now, type in your text
  
m =
n =
p =
  
(see Figure 3.10)
  
Clipboard12
Figure 3.10
   
Next you will put the other kind of text called “Dynamic Text” next to m, n, and z. Use the Text tool again and place it as in Figure 3.11.
  
Clipboard13
Figure 3.11
  
Change the text type to “Dynamic Text” as shown in Figure 3.12 below.
  
Clipboard14Figure 3.12 
  
Type “00” in your text box(Note: you can actually type anything in there, try it!) as seen in Figure 3.13.
  
Clipboard15 
Figure 3.13
  
If you look inside the properties tab, you can see the box labeled “Var:”. This is where you put your parameter in. For this case, you can put “x” in there as in Figure 3.14.
   
Clipboard16 
Figure 3.14
  
Do the same thing to n, and p. (see Figure 3.15)
  
Clipboard17
Figure 3.15 
  
And put Var: as y, and z, repectively for n and p. Now test your file by pressing Ctrl + Enter or go to Control –> Test Movie (see Figure 3.16)
   
Clipboard18 Figure 3.16
  
You will see your movie showing up as in Figure 3.17.
  
Clipboard19 
Figure 3.17
  
This is how you check values of your parameters. Keep it in mind that you have to put a parameter in “Var:” box to see the value you are checking for. In this case you can put

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