• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 17. Adding the Finishing Touches > Adding a Camera Backdrop

Adding a Camera Backdrop

A camera backdrop is a bitmap image—a texture actually—that gets placed behind all your 3D models. Using a backdrop is a good way to simulate such things as far-off trees and buildings, or the sky. It's also a simple way to add a background to a three-dimensional world, which is what we're going to do with the memory game.

Import bluegradient.png from the Lesson17\media folder on the CD. You can import it as 24 bits, as it has no alpha channel.

This image will serve as our background, behind the game board. Textures that are used for backdrops don't get scaled; the image is 800 × 600 in size to make sure it covers the area completely.

Right-click the 3D sprite and select Script from the context menu. Add the following two lines of code to the beginSprite handler. You can add the lines at the bottom of the handler:

bb = wrld.newTexture("blueback", #fromCastMember, member("bluegradient"))
sp.camera.addBackdrop(bb, point(0,0), 0)

You can actually add the code anywhere in the handler so long as you add it after the resetWorld() method is called. If you add it before resetWorld() then the second time the game is played you will receive an error when you try to create a texture that already exists.

First, a new texture named blueBack is created from the blueGradient cast member. A reference to the texture is stored in bb, and then used in the following line, which adds the texture to the camera's list of backdrops. (As this implies, you can have multiple backdrops, but you won't be using that feature here.)

Let's examine the line that adds the backdrop:

sp.camera.addBackdrop(bb, point(0,0), 0)

Remember, each 3D sprite shows a view of the 3D world through a particular camera and since sp is a reference to the 3D sprite, this adds the backdrop to the current view. The first parameter you pass in is, of course, a texture reference. Next, you specify the location of the backdrop's upper left corner. Because you want the image to fill the camera's view, point (0,0) will place the image at the top left. The final parameter specifies the rotation of the backdrop and because you don't want the gradient rotated, a 0 is passed in.

Rewind and play the movie.

When the movie plays, the gradient now appears behind the game board, and looks better than the simple black that was there previously.

Stop the movie and save it before continuing.

The game is now fully playable and could be made into a projector, or placed online in a Web page. But before you do that, I suggest you look through the next section for some ideas on making the game even better.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint