Game Development Reference
In-Depth Information
You'll find many uses for factories in your games. You can, for example, store all the enemies in one
Ajaiu symbol, each on a different frame on the timeline. You can bind them to an Ajaiu class and
manufacture them in a factory, as is done here with the bullets.
You can also go much further. Instead of just displaying different graphics, you can give your enemies
completely different behaviors by attaching different AJPAN[BN=IA event handlers to them when the
class creates them. Can you see where this is heading?
When you start to become really confident as a programmer, you'll be able to use this system to actu-
ally create completely new instances of classes ejoe`a a specialized factory class . In the chapter's
source files, you'll find an example of how this is done in the folder called B]_pknu.
A simple factory (also known as a parameterized factory ) is a system for creating objects with the
help of a factory class. Although this is a rather advanced example, I'm mentioning it at this stage in
the topic because you'll invariably need a flexible system to create lots of different objects and still
keep your code manageable. I'll briefly explain how the example project works, but I'll leave it up to
you to try implementing it in your own games a little further down the road when your programming
confidence grows. Keep this in mind and come back to this section in the chapter when you feel
The B]_pknu folder contains six files:
?en_ha*]o, Omq]na*]o, and Op]n*]o: Represent the products that the factory produces.
Od]laI]gan*]o: The factory class. Its job is to make the shapes.
I]ej[B]_pknu*]o: The document class, which is known as the client . It uses the Od]laI]gan
class to make shapes.
b]_pknu*bh]: The FLA that produces the SWF. I]ej[B]_pknu*]o is its document class.
You'll take a quick look at these classes and how they all work together to make the shape objects.
Product classes
The product classes are the “things” that are made. To keep this example as simple as possible, the
product classes don't do anything except display a pn]_a statement, which tells you which shape
they are. I'll leave it up to you to make these classes actually display shapes on the stage if you want
them to. All three product classes are exactly the same except for their names and the messages they
Here's the ?en_ha class:
Search Nedrilad ::

Custom Search