Flash CS4: Create a simple table tennis game

In this article, you'll use motion tween to create a simple table tennis game. The steps are as follows:

In this article, you'll use motion tween to create a simple table tennis game. The steps are as follows:

1. Switch back to the default workspace.

Click the Essentials area to reselect the default Flash workspace, then click Reset Essentials to restore this default workspace and start the exercise.

2. Create a new flash document.

3. Save a flash document.

Select the FLASH CS4 ONLINE folder, then save this file as 009_pingpong.fla

4. Import the drawing guide as a path for motion tween.

4.1. Select File > Import > Import to Stage . from the menu:

Picture 1 of Flash CS4: Create a simple table tennis game

4.2. In the Import dialog box, point to the file guide.jpg and click the Open button: (file guide.jpg attached to the card sized 550x400 pixels to use)

Picture 2 of Flash CS4: Create a simple table tennis game

You get the image of the links to help you create motion tween for the ball and the two bats later:

Picture 3 of Flash CS4: Create a simple table tennis game

Analysis of drawings:

In the figure above, the two vertical red lines represent the moving boundary of the ball. The ball can only touch these two lines and not pass.

The blue line shows the path of the ball. In this way, the ball moves from position 1 to position 2, 3, 4 and returns to position 5, where positions 1 and 5 overlap. The black line on the left shows the path of the left racket, the left racket moves from position 1, to position two to catch the ball and returns to position 3, where positions 1 and 3 overlap.

The black line on the right shows the path of the right racket, the racquet must move from position 1, to position two to catch the ball, then move forward to position 3, return to position 4 to catch the ball and return to position 5, in which positions 1 and 5 overlap.

Thus, the ball and the racket must use 5 keyframes, the left racket uses 3 keyframes.


5. Create motion tween for the ball.

5.1.Double-click Layer 1 to rename the Guide :

Picture 4 of Flash CS4: Create a simple table tennis game

5.2. Click the New Layer button in the Timeline to add a layer:

Picture 5 of Flash CS4: Create a simple table tennis game

5.3. Flash add a new layer with the default name Layer 2 . Double-click Layer 2 to rename it to Ball :

Picture 6 of Flash CS4: Create a simple table tennis game

5.4. Mouse over the toolbar. Click on the Rectangle Tool and hold down the mouse for a few seconds for the submenu to appear. Click on the Oval Tool :

Picture 7 of Flash CS4: Create a simple table tennis game

5.5 Click on the Stroke color box to select the border color for the oval:

Picture 8 of Flash CS4: Create a simple table tennis game

5.6. The color palette appears, click the box on the right with a red cross. This box is used to set the colorless value for the border, ie the drawn object has no borders:

Picture 9 of Flash CS4: Create a simple table tennis game

5.7 Click on the Fill color box to select the color for the oval:

Picture 10 of Flash CS4: Create a simple table tennis game

5.8. The color palette appears. You select the red pattern in the area containing the gradient color:

Picture 11 of Flash CS4: Create a simple table tennis game

You get the following result:

Picture 12 of Flash CS4: Create a simple table tennis game

5.10. Put your mouse on the upper corner, where the blue path of the ball comes from, hold down Shift and drag the mouse down to the right to draw a circle.

Picture 13 of Flash CS4: Create a simple table tennis game

Release the mouse button and you get the round ball with the gradient color as follows:

Picture 14 of Flash CS4: Create a simple table tennis game

5.11 Click on the Selection Tool on the right toolbar:

Picture 15 of Flash CS4: Create a simple table tennis game

5.12 Click on the ball just drawn. Once selected, the ball turns into tiny particles, while a four-dimensional arrow appears below the mouse:

Picture 16 of Flash CS4: Create a simple table tennis game

5.13. Select Modify > Convert to Symbol . from the menu (or press the shortcut F8 ) to convert the ball to symbol:

Picture 17 of Flash CS4: Create a simple table tennis game

The Convert to Symbol dialog box appears. Click on the name of the ball in the Name box, select Type as Movie Clip and click OK to close the dialog box. The ball is converted into a Movie Clip.

Picture 18 of Flash CS4: Create a simple table tennis game

5.14 Right click on the ball to bring up the context menu and select Create Motion Tween :

Picture 19 of Flash CS4: Create a simple table tennis game

Flash created a motion tween for the ball with 24 frames (equivalent to 1 second), while moving Playhead to frame 24 . You add additional frames so that the duration of the ball is long enough for you to observe. You will add the active ball to frame 60.

5.15 Move your mouse to frame 24 of layer Ball until the mouse turns into a two-way arrow:

Picture 20 of Flash CS4: Create a simple table tennis game

5.16 Drag to frame 60 , release the mouse button. You got motion tween for the ball with 60 frames :

Picture 21 of Flash CS4: Create a simple table tennis game

5.17 However, frame 60 is not yet a keyframe. In order for the contents of the first keyframe and the last keyframe of the ball to overlap, use the Up arrow key (up arrow) and the Down arrow (down arrow) on the keyboard. You press the Up arrow, the ball moves up 1 pixel, then you press the Down arrow, the ball moves below 1 pixel, Flash automatically adds keyframe at frame 60, and the ball position still doesn't change due to compensation:

Picture 22 of Flash CS4: Create a simple table tennis game

5.18 Click on frame 60 of layer Guide :

Picture 23 of Flash CS4: Create a simple table tennis game

5.19 Press the shortcut F5 to add more than 60 frames so that other layers can see the path that is on the layer Guide for easy operation:

Picture 24 of Flash CS4: Create a simple table tennis game

5.20 As discussed above, the ball uses 5 keyframes . You add the following keyframes: Drag your mouse to frame 15 on Timeline :

Picture 25 of Flash CS4: Create a simple table tennis game

5.21 Click to switch Playhead to frame 15 (note: click on 15, do not click on the frame on the layer):

Picture 26 of Flash CS4: Create a simple table tennis game

5.22 The mouse click drags the ball from position 1 to position 2 and drops it. Flash automatically add keyframe at frame 15 on layer Ball:

Picture 27 of Flash CS4: Create a simple table tennis game

5.23 Mouse over frame 30 on Timeline and click to switch Playhead to frame 30:

Picture 28 of Flash CS4: Create a simple table tennis game

5.24 Drag the ball to position 3. Flash automatically add keyframe at frame 30 on the Ball layer :

Picture 29 of Flash CS4: Create a simple table tennis game

5.25 Hover your mouse over frame 45 on Timeline and click to switch Playhead to frame 45 :

Picture 30 of Flash CS4: Create a simple table tennis game

5.26 Drag the ball to position 4. Flash automatically adds the keyframe at frame 45 on the Ball layer:

Picture 31 of Flash CS4: Create a simple table tennis game

You obtained the complete motion tween for the ball with the motion path purple as shown:

Picture 32 of Flash CS4: Create a simple table tennis game

Continue


6. Create motion tween for the left racquet.

6.1 Click the New Layer button in the Timeline to add a layer:

Picture 33 of Flash CS4: Create a simple table tennis game

6.2 Flash add a new layer with the default name Layer 3. Double-click Layer 3 to change its name to Left paddle :

Picture 34 of Flash CS4: Create a simple table tennis game

6.3 Move the mouse to the toolbar. Click on the Oval Tool and hold down the mouse for a few seconds for the submenu to appear. Click to select Rectangle Tool :

Picture 35 of Flash CS4: Create a simple table tennis game

6.4 Click on the Fill color box to select the color for the rectangle:

Picture 36 of Flash CS4: Create a simple table tennis game

6.5 The color palette appears. You choose the blue pattern:

Picture 37 of Flash CS4: Create a simple table tennis game

You get the following result (border color is still colorless):

Picture 38 of Flash CS4: Create a simple table tennis game

6.6 Click on the Stage , click on the corner of the starting position of the ball, drag backwards to the left and then release the mouse to get a rectangle, as shown below:

Picture 39 of Flash CS4: Create a simple table tennis game

6.7 Click the Selection Tool on the toolbar:

Picture 40 of Flash CS4: Create a simple table tennis game

6.8 Click to select the rectangle just drawn. Once selected, the rectangle changes to tiny particles, while the four-dimensional arrow appears below the mouse:

Picture 41 of Flash CS4: Create a simple table tennis game

6.9 Select Modify > Convert to Symbol . from the menu (or press the shortcut F8 ) to convert the rectangle to symbol :

Picture 42 of Flash CS4: Create a simple table tennis game

6.10 The Convert to Symbol dialog box appears. Type in the paddle name in the Name box, select Type as Movie Clip and click OK to close the dialog box. The rectangle is converted into a Movie Clip.

Picture 43 of Flash CS4: Create a simple table tennis game

6.11 Right-click the rectangle for the context menu to appear and choose Create Motion Tween . Flash created motion tween for the rectangle on the Left paddle layer with 60 frames:

Picture 44 of Flash CS4: Create a simple table tennis game

6.12 Mouse over frame 60 on Timeline and click to switch Playhead to frame 60:

Picture 45 of Flash CS4: Create a simple table tennis game

6.13 Frame 60 is still not a keyframe. You press the Up arrow, the rectangle moves over 1 pixel, then you press the Down arrow, the rectangle moves below 1 pixel, Flash automatically adds keyframes at frame 60, and also positions the shape Japan has not changed because it has been offset:

Picture 46 of Flash CS4: Create a simple table tennis game

6.14 Hover your mouse over frame 30 on Timeline and click to switch Playhead to frame 30:

Picture 47 of Flash CS4: Create a simple table tennis game

6.15 Hold down the Shift key and drag the rectangle to position 2, where the ball is located (Shift key helps you to move vertically, not to the right or left):

Picture 48 of Flash CS4: Create a simple table tennis game

So you've finished motion tween for the left racket (ie rectangle).


7. Create motion tween for the right racquet.

7.1 6.1 Click the New Layer button in the Timeline to add a layer:

Picture 49 of Flash CS4: Create a simple table tennis game

7.2 Flash add a new layer with the default name Layer 4. Double-click Layer 4 to rename to Right paddle :

Picture 50 of Flash CS4: Create a simple table tennis game

7.3 Click the Library tab to open the Library Panel :

Picture 51 of Flash CS4: Create a simple table tennis game

7.4 From the Library Panel , drag the Movie Clip paddle to the Stage , and drop it into position 1 of the racquet right as shown:

Picture 52 of Flash CS4: Create a simple table tennis game

7.5 Click the right mouse button on the right racket (ie rectangle) to bring up the context menu and select Create Motion Tween .

Picture 53 of Flash CS4: Create a simple table tennis game

7.6 Mouse over frame 60 on Timeline and click to switch Playhead to frame 60 :

Picture 54 of Flash CS4: Create a simple table tennis game

7.7 Frame 60 is not yet a keyframe. You press the Up arrow, the rectangle moves over 1 pixel, then you press the Down arrow, the rectangle moves below 1 pixel, Flash automatically adds keyframes at frame 60, and also positions the shape Japan has not changed because it has been offset:

Picture 55 of Flash CS4: Create a simple table tennis game

7.8 Hover your mouse over frame 15 on Timeline and click to switch Playhead to frame 15 :

Picture 56 of Flash CS4: Create a simple table tennis game

7.9 Hold down Shift and drag the racquet to where the ball is in position 2:

Picture 57 of Flash CS4: Create a simple table tennis game

7.10 Mouse over frame 30 on Timeline and click to switch Playhead to frame 30 :

Picture 58 of Flash CS4: Create a simple table tennis game

7.11 Hold Shift and drag the racquet to position 3 as shown:

Picture 59 of Flash CS4: Create a simple table tennis game

7.12 Hover your mouse over frame 45 on Timeline and click to switch Playhead to frame 45 :

Picture 60 of Flash CS4: Create a simple table tennis game

7.13 Hold Shift and drag the racquet to the place where the ball is in position 4 as shown:

Picture 61 of Flash CS4: Create a simple table tennis game

So you've finished motion tween for the right racket.


8. Move layer Guide to Guide Layer.

Layer Guide has completed the task. You can delete this layer. However, you can keep it for reference by converting it to Guide Layer:

8.1 Right-click the layer guide to bring up the context menu and select Guide :

Picture 62 of Flash CS4: Create a simple table tennis game

Flash to change the icon of the layer Guide into a hammer. In this way, the content of the layer Guide will not be exported to Flash Movie, does not increase the size of your work.

Picture 63 of Flash CS4: Create a simple table tennis game

8.2 Select Control > Test Movie from the menu (or shortcut Ctrl + Enter ) to see the result:

Flash will export to file 009_pingpong.swf as follows:

Picture 64 of Flash CS4: Create a simple table tennis game

9. Move motion path

If you do the right actions as instructed, when you test Movie you will see the left racket has not touched the ball. You will move the motion path of the left racket to the racquet to hit the ball (you can get the attached sample file to practice this step)

9.1. Hover your mouse over frame 30 on Timeline and click to switch Playhead to frame 30 :

Picture 65 of Flash CS4: Create a simple table tennis game

You see the left racquet a paragraph away from the ball:

Picture 66 of Flash CS4: Create a simple table tennis game

9.2 Press the selector on the left rack to show motion path :

Picture 67 of Flash CS4: Create a simple table tennis game

9.3 Double-click motion path :

Picture 68 of Flash CS4: Create a simple table tennis game

9.4 You check in the Property Inspector to have Motion Tween icon to make sure you have selected motion path , not any other object:

Picture 69 of Flash CS4: Create a simple table tennis game

9.5 Use the right arrow key ( Right ) on the keyboard to move the racquet to the right until the racquet hits the ball. Each time you press the Right key, the object moves 1 pixel, if you hold down the Shift key, the object moves 10 pixels.

Picture 70 of Flash CS4: Create a simple table tennis game

You can do the same way to apply to the right racket.

Suggested exercises:

Redo the above lesson with the change guide as shown below. This time both racquets move with keyframe positions marked on the illustration. You can download the guide2.jpg illustration and sample result file 009_pingpong2.fla for reference.

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile