Flash Animation | induction
Demo Effect:(Press the SPACEBAR on the keyboard to see the effect)
/uploadpic/2007-7/20077812214954.swf
Click here to download the source file
First: Change the background to size 300x301
Draw the shape of a tank:
Select it to press F8 to change to a movie clip. Create a new movie clip the first frame is a blank frame; code: Stop ();
The second frame is this:
Create a new movie clip and drag two things out of the library:
The small point is used for firing, naming it huo. To the most important place, is also the longest code place. Drag the just-done MC into the scene and enter the code:
Onclipevent (load) {
Speed = 5;
}
Onclipevent (enterframe) {
if (Key.isdown (key.left) and! Key.isdown (Key.right)) {
_x-= Speed;
_rotation = 270;
}
if (Key.isdown (key.right) and! Key.isdown (Key.left)) {
_x + = Speed;
_rotation = 90;
}
if (Key.isdown (key.up) and! Key.isdown (Key.down)) {
_y-= Speed;
_rotation = 0;
}
if (Key.isdown (Key.down) and! Key.isdown (key.up)) {
_y + = Speed;
_rotation = 180;
}
if (Key.isdown (Key.left) and Key.isdown (key.up) and! Key.isdown (key.right) and! Key.isdown (Key.down)) {
_rotation = 315;
}
if (Key.isdown (key.right) and Key.isdown (key.up) and! Key.isdown (key.left) and! Key.isdown (Key.down)) {
_rotation = 45;
}
if (Key.isdown (Key.left) and Key.isdown (Key.down) and! Key.isdown (key.right) and! Key.isdown (key.up)) {
_rotation = 225;
}
if (Key.isdown (key.right) and Key.isdown (Key.down) and! Key.isdown (key.left) and! Key.isdown (key.up)) {
_rotation = 135;
}
if (_x<-5) {
_x = 301;
}
if (_x>306) {
_x = 0;
}
if (_y>305) {
_y = 0;
}
if (_y<-5) {
_y = 300;
}
if (Key.isdown (Key.space)) {
With (Huo) {
gotoAndPlay (2);
}
}
}
Don't be afraid, such a long code is very simple. Here is the annotated code:
Onclipevent (load) {
Speed = 5;
Beginning words speed (originally want to use SP, a think is curse, haha)
}
Onclipevent (enterframe) {
if (Key.isdown (key.left) and! Key.isdown (Key.right))//Avoid error {
_x-= Speed;
_rotation = 270;
}
if (Key.isdown (key.right) and! Key.isdown (Key.left))//Avoid error {
_x + = Speed;
_rotation = 90;
}
if (Key.isdown (key.up) and! Key.isdown (Key.down))//Avoid error {
_y-= Speed;
_rotation = 0;
}
if (Key.isdown (Key.down) and! Key.isdown (Key.up))//Avoid error {
_y + = Speed;
_rotation = 180;
}
To set the _rotation code, just copy the changes
if (Key.isdown (Key.left) and Key.isdown (key.up) and! Key.isdown (key.right) and! Key.isdown (Key.down)) {
_rotation = 315;
}
if (Key.isdown (key.right) and Key.isdown (key.up) and! Key.isdown (key.left) and! Key.isdown (Key.down)) {
_rotation = 45;
}
if (Key.isdown (Key.left) and Key.isdown (Key.down) and! Key.isdown (key.right) and! Key.isdown (key.up)) {
_rotation = 225;
}
if (Key.isdown (key.right) and Key.isdown (Key.down) and! Key.isdown (key.left) and! Key.isdown (key.up)) {
_rotation = 135;
}
For a spin code, why add 5, because the 5 can make it a little more natural
if (_x<-5) {
_x = 301;
}
if (_x>306) {
_x = 0;
}
if (_y>305) {
_y = 0;
}
if (_y<-5) {
_y = 300;
}
For fire, so I just taught you to make fire.
if (Key.isdown (Key.space)) {
With (Huo) {
gotoAndPlay (2);
}
}
}
Well, the main finished, landscaping.