Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Activetuts+. This tutorial was first published a long time ago in May, 2009.
In this tut I'll describe how to create a basic 3D scene using the native 3D options of Flash Player 10. Then I'll explain how to add interactivity to the elements and set up a basic pong game. Let's go..
Step 1: Setting the Scene
Let's set up the stage and create the 3D scene. In a regular pong game the ball bounces off the top and bottom of the screen, but since we're adding some perspective to the mix we'll need to provide these borders too. There are five movieclips needed: the floor and the four walls (two of which are actually paddles). The registration points of the walls should all be located against the floor. You can create all of these simply with the rectangle tool or use an imported bitmap image (remember to turn on "Allow smoothing" in the properties). Make a movieclip out of each of the walls and give them an instance name (I named them "wallTop", "wallBottom", "wallLeft" and "wallRight" and will refer to them later). Name the background "floor".
Select all the walls and the floor, create one big movieclip out of those and name it "bg".
To display the score later on we'll also need two dynamic text fields. If you place these within the "bg" movieclip they'll also have the 3D perspective. Name these "scoreLeft" and "scoreRight" then embed the fonts.