AS actual articles
-----------------------------------
If you just start learning AS, and I haven't seen the three tutorials in front of me, here is connected:
Tuner AS Getting Started Tutorial
This time we have to enter the actual combat, I want to teach you to do a very simple game, everything in the following, I will add a comment, if you have seen the tutorial above, I want all the understanding should not be difficult.
Let us start now. This game is a game made by the tutorial when I start school, so the impression is profound. This game is called a snail race. The process is like this: there are several tracks on the screen, and there is a snail on each track, and each snail crawling is different. The game starts, you have to guess which snail will run to the end. If you guess, you win, otherwise, Game over.
Step 1, let's set the size of 600 * 400 px first, running speed is 48 frames / second this is my personal preference speed.
Step 2, we change the default layer name to bkground, and draw a track, starting line, and finish line, I am 4 tracks here.
Step 3, create a new layer, named Wn_Layer, then draw a movable snail on this layer, F8 defines into MC, MC is named Wn_MC. Put the tail of the snail throughout the MC, if you have, the snail is over the end of the end. Then copy 3 the same snail, adjust the color in the attribute bar, so that they look a bit different. Then put it to the starting point of each track.
Step 4, create a new layer, name BTN, then make a button, copy 4 respectively, next to 4 snails.
Step 5, remember the X-axis position data started by the snail, I am 25, then drag a snail to the end to see how much its X-axis position data, then write down, prepare for AS. I got here 540. Remember to put it back ~
Step 6, create a new layer, named ACTOINS, used to write AS. This layer we take 4 keyframes. Let me talk about why.
We need a frame to prepare to start the game, that is, let the player guess the frame, is a snail that the game starts. This is completed by the first frame. The 4 buttons we have made are to let the players guess which snail will win.
When the game starts, the player can't change the data, so in the process of turtle, the button layer has no content.
The second frame we have to let each snail climb all once, why only let them climb again? Because the pointer of the time axis passes this key frame, only the AS inside the frame is once. In order to let the snail continue to climb, we need to repeat the time pointer to the second frame, so our third frame content is to return the time pointer back to the second frame.
After the third frame, the frame is displayed. Then we create a new layer, named show, do the 4th and 5th keyframes, put a victory in the 4th frame, put a failed word on the 5th frame .
In addition, after the game is over, we need a button to let the player play again, so the 4th to 5 frames of the button layer require a button.
After the arrangement, the structure of the entire layer is as shown in the figure (yet no AS):
Now we have 4 objects: _Root.wn1, _root.wn2, _root.wn3, _root.wn4
Let's do one frame below:
Action first frame
_root.stop (); // Stop time axis
_root.truewinner = 0;
_Root.guesswinner = 0;
The 2 sentences in the following sentence define two variables Truewinner, Guesswinner in _root Time axes. Variables are used to store data and can be defined by themselves. The Truewinner, Guesswinner here, indicates which number is guessing and players. These two data are initialized here. Action frame 2
_root.wn1._x = random (10) / 10 random (1); // Snail 1 X-axis data adds a value
_Root.wn2._x = random (10) / 10 random (1); // Snail 2 X-axis data increases a value
_Root.wn3._x = random (10) / 10 random (1); // Snail No. 3 X-axis data adds a value
_Root.wn4._x = random (10) / 10 random (1); // Snail 4 X-axis adds a value
I have seen the object articles, I understand it here?
_X represents one of the properties of the object snail: the location of the X axis.
= Is self-added, so understanding A = A 1 and A = 1 are the same. Represents self-add 1.
There is a method here, Random ()
This method is used to get a random number, such as Random (10) to get any of the numbers in the middle of 0-9. The above expression gets a random number from 0-1.9.
Action third frame
IF (_ROOT.WN1._X> 540) {
_root.truewinner = 1;
}
IF (_ROOT.WN2._X> 540) {
_root.truewinner = 2;
}
IF (_root.wn3._x> 540) {
_root.truewinner = 3;
}
IF (_root.wn4._x> 540) {
_root.truewinner = 4;
}
// Judgment which snail is coming, change the value of Truewinner, and record which snail wins
IF (_root.truewinner! = 0) {
IF (_Root.guesswinner == _root.truewinner) {
_Root.gotoAndStop (4);
} else {
_Root.gotoAndStop (5);
}
} else {
_Root.gotoAndPlay (2);
}
/ * --------------------------------------------
Judging the value of Truewinner, if it is changed, it shows that there is no snail to
If there is no change, it means that the snails have not arrived yet.
If you don't arrive, you jump to the 2nd frame, let them continue to run, if it is.
It is just the same as the player who is pressed with the truly. If you guessed, let the time
Pointer jumps to the 4th frame, otherwise the jump to the 5th frame.
-------------------------------------------- * /
Carefully understand the process, it should be difficult :)
Next is the AS on the button:
Frame of the button
On (Release) {
_Root.Play ();
_Root.guesswinner = 1;
}
The first snail next to the button on the AS. When the button is released, the pointer jumps to the second frame, then the record variable Gueswinner is 1 (guess the first).
The code next to other snails is similar to the record variable guesswinner value of 2, 3, 4
The last button is used to replay.
On (Release) {
_Root.gotoAndStop (1); _ root.wn1._x = 25; // Snail 1 backward point
_root.wn2._x = 25;
_root.wn3._x = 25;
_Root.wn4._x = 25;
}
Do you understand? Well, see what I did.
Here I will not give the source file, everyone do it yourself, very accomplishment ~ :)
(Finish)