Flash game Kill Dog Contest making

Source: Internet
Author: User
Tags insert rounds

In the internet is extremely hot today, the network technology changes rapidly, and Macromedia Flash is undoubtedly one of the best, flash technology to unparalleled speed by the vast number of users to accept, and increasingly show its strong vitality.

It provides designers and developers with easy to create new generation of Web applications editing experience. From Coca-Cola, Ai Hua Electronics, more and more users choose Flash to make high compression, rich in sound and animation interactive website. Creative, interactive, fun, practical, everything is so perfect ....

But want to learn flash, its shape changes the picture, the motion animation, the mask animation and so on is not difficult, the biggest difficulty is undoubtedly in Macromedia The ActionScript scripting feature embedded in flash5.0, the ActionScript scripting language is a very powerful network animation programming language, and its syntactic structure is similar to that of JavaScript scripting languages, but there are many unique features that are different from JavaScript. More than 50 action actions, hundreds of substring strings, operators and functions, and a lot of books, tutorials too long, abstract, it is difficult for a time to fully understand.

The purpose of this article is to use a few simple flash games, so that users who have mastered the basic operation of Flash have a more direct understanding of the Actionscrip script, master the commonly used ActionScript scripting language, and through more hands, more brain, In actual combat to improve their flash level.

Example Description:

This game has 9 burrows, puppy random in these 9 holes appear, your task is in the puppy head retract hole before hit it, the faster hit score higher, puppy every time for a round, 20 rounds after the game is over, and give a score.

  Principle Analysis:

Using a mask to complete the puppy in a black hole in the effect of a, with StartDrag to replace the mouse, using Ramdon to take random numbers to make puppies randomly appear, and the timeline on each frame to give a different score so that the faster hit the points higher, and finally use input text to show the score. I hope you can understand the principle of the game, rather than simply do, extrapolate is very important, only really understand the principle of a work, the algorithm, you can make your own better works. For you to see more clearly and make it suitable for some flash beginners,
I will explain and describe the operation in a layer-by-layer, as detailed as possible, as the order of the explanations is the same as the order in which we actually complete a piece of work, so it is necessary to draw attention to:

Background Layer

Open your flash, this example uses the Macromedia flash5.0 version, click File, and in the Drop-down menu, click New to create a new file. (These operations have shortcut keys, for you to better understand, will be written as file---new, the same below) modify---movie, the movie information appears in the film width (width) to 400, height (height) to 300, and set the background color is light yellow. Insert---symbol ... Create a new figure (graphic) original name hole, draw a black oval in hole, return to scene 1,window---library display the original list, drag the hole to the first level of scene 1, and copy it into 9. Window---Panels---Align the alignment panel to align the 9 hole, and then use the Text tool to
Enter the "score" at the bottom right, and finally rename the layer to background.

Dog Layer

Insert---symbol ... New graphic named Dogpic, hand-painted a lovely dog head, of course, if you like piglet I don't mind. Inster---symbol ... New keys A movieclip, named Dogmovie, dragged from the library dogpic to Dogmovie, the bureau. Insert---keyframe a keyframe in frame 5,10,25, click Frame 10th to adjust the position of dogpic on this frame up to 50 (available by window---panel---info). Insert---keyframe to build keyframes in frame 20th. Right-click any frame between frames 5th through 10th, creat motiontween Create motion animations, and also create motion animations in frame 20th to 25th. Inster---symbol ... Create a button named Grid,insert---keyframe a key frame on the hit frame, draw a moment type. Return to Pigmovie,insert---layer a new layer of Layer2,insert---keyframe build keyframes in frame 5th, drag grid to Lyer2 from the library, and delete 21-25 frames from the lyer2. Insert---Layer create a new layer of Lyer3,insert---blank keyframe set up a blank keyframe in the 1,5,20 frame, and left-click the first frame to eject the action panel,
Basic Action---Stop, click Frame 5th, Window---panel---frame to eject the frame panel, set the lable to up, and also set the frame lable of 20 frames to down. We are here to set the lable value for the frame is to facilitate our use of ActionScript to jump, in Flash can be set by the number of frames or frame tags jump, usually using the label way, You can reduce the chance of errors and make your ActionScript more readable. We go back to scene 1,insert---layer new layer renamed dog, drag and drop from the library Dogmovie to this layer, copy 9, so that each dogmovie is exactly in the background layer of each of the black oval axis below.

Mask Shading Layer

The concept of masking is that a mask layer can mask the contents of any layer that is associated with the mask layer (the masked layer).
Insert layer in Scene 1 and rename this layer to mask, drawing a rectangle based on the black oval long axis on the background layer, and making the moment larger than the Dogmovie, copying nine permutations. Right-click this layer to select Mask in the pop-up menu, so that we have a cover. That is to say, all originals on the dog layer are not visible unless they appear within 9 rectangles of this layer. Since there are no originals on the dog floor in this range, so although we put 9 originals on the dog layer, we'll only see
There are 9 black hole on the background layer, but remember, what we do Dogmovie is the movieclip that moves up and down, and when it moves up the cloud is displayed on the screen, and the downward motion disappears from the screen. That's how we get the puppy to come in. But there is a serious problem, our 9 Dogmovie will be moving at the same time, not as we want one of the movement, don't worry, the following is our protagonist ActionScript appearance.

Random Motion

Double-click the first frame in the Pigmovie and select Stop () in the Action Panel's basic action.
Click a dogmovie,window---panels on the dog layer---instance to set name to Dog0. The other dogmovie are named Dog1,dog2.....dog8 in turn. Create a new action in Scene1, create a new Guan Jianli in frame 5th, double-click Frame 5th, and then enter the following actions:

Telltarget ("/dog" Add random (9)) {
gotoAndPlay ("Up");
}

Random (9) is a number from 0-9, add is a word Fu connector, used to connect the "/dog" and Random (9) the number obtained. The syntax for Telltarget is:

Telltarget (target);

Target: Specify the destination path string for the time axis
Statement: Target Time axis code
The result of the execution of Telltarget ("/dog" Add random (9)) is to call/dog0,/dog1....../dog8, and gotoAndPlay ("Up") starts playing from the up frame, which is
We dogmovie randomly appear in the target place.

Mouse Replacement

To make the game more realistic, we should screen out the default mouse graphics and replace it with the movieclip we do. Insert---symbol first ... Create a new Moviclip original named knife, double-click the first frame, select Stop () in basic action in the action panel, draw a knife in the second frame, and draw a bunch of blood on the edge of the knife in the third frame. Go back to Scene1, drag the knife to the background layer, and name it knife, build the keyframe on the 4th frame of the action layer, and enter the following actions:

Mouse.hide ()
StartDrag ("Knife", true);

Mouse.hide () hides the default mouse. The syntax for StartDrag is:

StartDrag (target);
StartDrag (Target,[lock]);
StartDrag (Target,[,lock[,left,top,right,bottom]]);

Target: Destination path for movie clip to be dragged
Lock: A Boolean value that specifies whether the dragged movie clip is locked in the center of the mouse (true), or where the user initially clicks on the movie clip (false).
This parameter is optional.
Left,right,top,bottom: Specifies the restricted rectangular area of the animation's parent movie clip. This parameter is optional.
So we can use knife to replace the default mouse.

Scoring and rounds:

We ordered the game to end after 10 rounds, and the score and total score for each round were calculated. Game over after 10 rounds. First, let's look at how to achieve the calculation game round:
Double-click the fourth frame input on the action layer: round= "0", click 5th Frame on the frame panel to define lable as: Again, create keyframes in frame 30th, and define their frame lable as back. Double-click the 26th frame on the action layer to enter the following actions:

ROUND = number (ROUND) +1;
if (number (ROUND) <11) {
gotoAndPlay ("Again");
} else {
gotoAndPlay ("Back");
}

This allows us to complete the loop with a conditional selection. When the round is less than 11 o'clock the loop will continue, and round equals 11 o'clock will skip to the end.

The way the game is scored is the faster you hit the puppy score.

Create a new layer named point in Scene1, build KeyFrames from frames 5th through 25th, and then click

Actions are as follows: "Point=", point= "190" ... Point= "0".
Create a new layer named text in Scene1, drag a text box with Text Tool, window---panels---text opion, define the text box as input text in the text opion panel,
Varable for score. Double-click the action layer frame 25th and enter the following actions:
Tatal = number (tatal) +number (point);
Score = Tatal;

Where Tatal is the total score, point is the score, and number is a function in the actions that converts the value of a parameter, a variable, or an expression to numeric values. and score = Tatal allows us to display the score Tatal value in the Score text box.

Mouse Action:

The question now is how we can make flash know whether we hit the puppy, whether it scores, and once we hit the puppy, the puppy should drill back into the black hole right away. To achieve this effect, obviously we should use the mouse action. Remember the button grid we joined in the Dogmovie when we started? Start editing the Dogmovie original, create a new layer of lable, set the frame lable to the up of frames 5th, and set the frame lable of frame 20th to down. Finally, add the following actions to the button grid:

On (release) {
gotoAndPlay ("Down");
Telltarget (".. /knife ") {
gotoAndPlay ("Up"); }
Telltarget ("..") {
gotoAndPlay ("End");
}
}

The syntax on is:

On (MouseEvent)

Statement: Code to execute when a mouse event occurs
MouseEvent is a mouse event, including:
Press: The mouse pointer is over the button and click
Release: The mouse pointer is released on the button
Releaseoutside: The mouse pointer is released outside the button
Rollover: Move the mouse pointer into the button area
Rollout: Move the mouse pointer out of the button area
DragOver: The mouse pointer is pressed on the button, moved out of the button and then moved back
KeyPress: The mouse pointer is over the button, then the mouse is pressed, and then the button area is removed.

The implication of this move is that when this button is clicked by the mouse, the movie jumps to the framelable for down frame to start playing, instead of the mouse animation MovieClip starts at frame lable as
Up, and scene1 jumps to the frame lable to play at the end.

Add music

For a game, music is indispensable. First, let's analyze what you need and what kind of music you need. First of all must have background music, and when hit the puppy should also sound effect of the match. Go back to scene 1,file---import, importing your favorite background music, note that it is best to import mp3 format files so that your source files are not too large, and the length of the music is best as long as your film, according to your video playback speed (such as the frames/seconds), You can calculate the approximate playback time and use it as a basis for finding music.
Create a new layer named sound in Scene1, drag music from the Library to sound, window---panels---sounds pop-up sound panel, set as stream in sync so that concerts and animations play synchronously, There's no big distortion. Edit Knife Original, create a new layer, file---Imports, import your favorite sound, create a new keyframe in frame 2nd, drag the sound from the library to the frame.

Good! Now complete the production of the whole game, I hope this article can familiarize you with the basic operation of Flash, to understand ActionScript syntax help.



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.