Game Development Reference
In-Depth Information
Another of AS3.0's built-in methods that you'll certainly find use for in your games is os]l?deh`naj.
You can swap the position of two objects in the display list by using a line of code that looks like
This code makes the two objects change places in the list. You're not using os]l?deh`naj in this game,
but it's important to keep it in mind. It's always useful when you need to make one object appear
above or below another object without having to know their actual positions in the list.
Adding some bugs to the code—literally!
Now that you have a fun environment to play in, let's start to turn this into a real game. In my Bug
Catcher game, I created three little bug Movie Clip symbols: Bhu, >aa, and Ikomqepk. These symbols
are all exactly the same except for their colors. They each contain a one-frame animation that flaps
their wings. I added them to the stage and gave them the instance names bhu, ^aa, and ikomqepk.
In the Dungeon Maze Adventure game from Chapter 8, all the important game objects had their
own class. Although that's probably a preferable approach to take for most games because it really
does help to break down complexity into manageable chunks, it can be overkill for a very small game
such as Bug Catcher. In Bug Catcher, all the objects, except from the lh]uan, are programmed in the
I]ej[>qc?]p_dan class. There are a few reasons for this:
You need to see how this can be done. It's often quicker and easier to work through ideas with
all the code in one big class, such as I]ej. Once you understand how some of the code is work-
ing, you can then break it down into classes. It's a good experimental lab.
You're learning a few new techniques, and their effects will be clearer if all the code is in one
Truth be told, this is a better way to work for very small games. It's much less code and it can
be easier to make quick changes than working with many classes. The chance of bugs occurring
(programming bugs!) because of code dependency is mitigated by the fact that the game is so
When you're designing your games, you'll need to decide whether you want to take a more
object-oriented route, as with Dungeon Maze Adventure, or a more procedural route, as with Bug
Catcher. If Bug Catcher were even just slightly bigger, I would have broken it down into smaller
Here's how to program the bugs in the game:
Dynamically create rt and ru properties for each of the bugs, directly in the constructor
Attach an AJPAN[BN=IA event to each bug to control the bug's movement and artificial
Let's first add the bugs to the stage, create the properties, and add the event listeners:
1. Add instances of the three bugs to the stage and give them the instance names bhu, ^aa, and
Search Nedrilad ::

Custom Search