The method of making Flash animation with keyboard induction

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.