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:

images 1 of Flash CS4: Create a simple table tennis game
Images 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)

images 2 of Flash CS4: Create a simple table tennis game
Images 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:

images 3 of Flash CS4: Create a simple table tennis game
Images 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 :

images 4 of Flash CS4: Create a simple table tennis game
Images 4 of Flash CS4: Create a simple table tennis game

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

images 5 of Flash CS4: Create a simple table tennis game
Images 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 :

images 6 of Flash CS4: Create a simple table tennis game
Images 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 :

images 7 of Flash CS4: Create a simple table tennis game
Images 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:

images 8 of Flash CS4: Create a simple table tennis game
Images 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:

images 9 of Flash CS4: Create a simple table tennis game
Images 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:

images 10 of Flash CS4: Create a simple table tennis game
Images 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:

images 11 of Flash CS4: Create a simple table tennis game
Images 11 of Flash CS4: Create a simple table tennis game

You get the following result:

images 12 of Flash CS4: Create a simple table tennis game
Images 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.

images 13 of Flash CS4: Create a simple table tennis game
Images 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:

images 14 of Flash CS4: Create a simple table tennis game
Images 14 of Flash CS4: Create a simple table tennis game

5.11 Click on the Selection Tool on the right toolbar:

images 15 of Flash CS4: Create a simple table tennis game
Images 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:

images 16 of Flash CS4: Create a simple table tennis game
Images 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:

images 17 of Flash CS4: Create a simple table tennis game
Images 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.

images 18 of Flash CS4: Create a simple table tennis game
Images 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 :

images 19 of Flash CS4: Create a simple table tennis game
Images 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:

images 20 of Flash CS4: Create a simple table tennis game
Images 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 :

images 21 of Flash CS4: Create a simple table tennis game
Images 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:

images 22 of Flash CS4: Create a simple table tennis game
Images 22 of Flash CS4: Create a simple table tennis game

5.18 Click on frame 60 of layer Guide :

images 23 of Flash CS4: Create a simple table tennis game
Images 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:

images 24 of Flash CS4: Create a simple table tennis game
Images 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 :

images 25 of Flash CS4: Create a simple table tennis game
Images 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):

images 26 of Flash CS4: Create a simple table tennis game
Images 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:

images 27 of Flash CS4: Create a simple table tennis game
Images 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:

images 28 of Flash CS4: Create a simple table tennis game
Images 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 :

images 29 of Flash CS4: Create a simple table tennis game
Images 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 :

images 30 of Flash CS4: Create a simple table tennis game
Images 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:

images 31 of Flash CS4: Create a simple table tennis game
Images 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:

images 32 of Flash CS4: Create a simple table tennis game
Images 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:

images 33 of Flash CS4: Create a simple table tennis game
Images 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 :

images 34 of Flash CS4: Create a simple table tennis game
Images 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 :

images 35 of Flash CS4: Create a simple table tennis game
Images 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:

images 36 of Flash CS4: Create a simple table tennis game
Images 36 of Flash CS4: Create a simple table tennis game

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

images 37 of Flash CS4: Create a simple table tennis game
Images 37 of Flash CS4: Create a simple table tennis game

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

images 38 of Flash CS4: Create a simple table tennis game
Images 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:

images 39 of Flash CS4: Create a simple table tennis game
Images 39 of Flash CS4: Create a simple table tennis game

6.7 Click the Selection Tool on the toolbar:

images 40 of Flash CS4: Create a simple table tennis game
Images 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:

images 41 of Flash CS4: Create a simple table tennis game
Images 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 :

images 42 of Flash CS4: Create a simple table tennis game
Images 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.

images 43 of Flash CS4: Create a simple table tennis game
Images 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:

images 44 of Flash CS4: Create a simple table tennis game
Images 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:

images 45 of Flash CS4: Create a simple table tennis game
Images 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:

images 46 of Flash CS4: Create a simple table tennis game
Images 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:

images 47 of Flash CS4: Create a simple table tennis game
Images 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):

images 48 of Flash CS4: Create a simple table tennis game
Images 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:

images 49 of Flash CS4: Create a simple table tennis game
Images 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 :

images 50 of Flash CS4: Create a simple table tennis game
Images 50 of Flash CS4: Create a simple table tennis game

7.3 Click the Library tab to open the Library Panel :

images 51 of Flash CS4: Create a simple table tennis game
Images 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:

images 52 of Flash CS4: Create a simple table tennis game
Images 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 .

images 53 of Flash CS4: Create a simple table tennis game
Images 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 :

images 54 of Flash CS4: Create a simple table tennis game
Images 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:

images 55 of Flash CS4: Create a simple table tennis game
Images 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 :

images 56 of Flash CS4: Create a simple table tennis game
Images 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:

images 57 of Flash CS4: Create a simple table tennis game
Images 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 :

images 58 of Flash CS4: Create a simple table tennis game
Images 58 of Flash CS4: Create a simple table tennis game

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

images 59 of Flash CS4: Create a simple table tennis game
Images 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 :

images 60 of Flash CS4: Create a simple table tennis game
Images 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:

images 61 of Flash CS4: Create a simple table tennis game
Images 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 :

images 62 of Flash CS4: Create a simple table tennis game
Images 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.

images 63 of Flash CS4: Create a simple table tennis game
Images 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:

images 64 of Flash CS4: Create a simple table tennis game
Images 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 :

images 65 of Flash CS4: Create a simple table tennis game
Images 65 of Flash CS4: Create a simple table tennis game

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

images 66 of Flash CS4: Create a simple table tennis game
Images 66 of Flash CS4: Create a simple table tennis game

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

images 67 of Flash CS4: Create a simple table tennis game
Images 67 of Flash CS4: Create a simple table tennis game

9.3 Double-click motion path :

images 68 of Flash CS4: Create a simple table tennis game
Images 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:

images 69 of Flash CS4: Create a simple table tennis game
Images 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.

images 70 of Flash CS4: Create a simple table tennis game
Images 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.

5 | 1 Vote
« PREV : Flash CS4: Learn...
Flash CS4: Rectangle... : NEXT »