Game Development Reference
In-Depth Information
The op]ca object has to be typed as K^fa_p and not Op]ca* Because the @n]c]^haK^fa_p class isn't on
the stage, it can't access the Op]ca class, even if the Op]ca class is just needed to assign the object's
In the I]ej document class, you then create the dragable [omq]na object with two arguments, like
This includes the op]ca as one of the arguments.
If you want to take a look at how the little drag-and-drop sample looks written entirely using com-
position, open up the @n]c]j`@nkl/Ì?kilkoepekj folder in this chapter's source files. It's very
interesting to compare how it works with the previous two examples.
Composition is a very powerful object-oriented technique because any objects can share a class at
any time in your program without having to hard-code the class into the symbol properties. This also
means that if you decide, for example, that you want any of your enemy objects to suddenly take on
all the qualities of the player's class in the middle of a game, you can just feed them into that class
using composition. Another not-so-obvious advantage is that the class your objects use can extend any
class they choose (or none at all). They don't have to extend the class of the containing object, such
as Ikrea?hel. This gives your classes more flexibility to extend whatever other classes they please. All
this helps to whittle away at the problem of code dependency discussed in Chapter 8. Composition
This has been an extremely brief and very condensed introduction to composition, so don't worry too
much if you don't understand it thoroughly right away. Spend a bit of time looking at the example in
the source files, mull over them a bit and do a bit of experimenting on your own. You'll soon get an
appreciation for the beauty of this system.
Moving objects with the mouse
The AS3.0 drag-and-drop system is very convenient, but it has some limitations. Because the object's
position is updated independently of the movie's frame rate, all the little bells and whistles (such as
physics simulations and collision detection) that you expect to be able to apply to an object while it's
being dragged won't work. Because of this, many developers of drag-and-drop games end up building
their own drag-and-drop engines using the AS3.0 Ikqoa and IkqoaArajp classes.
But aside from drag-and-drop interfaces, games that use the mouse are just so much fun to play! In
fact, if you start designing Flash games professionally, your clients will probably expect that the game
controls rely on the mouse instead of the keyboard, and if you can design game controls using the
mouse exclusively, you're only a small step away from designing games for touch screen interface
devices, such as the iPhone or Nintendo DS. One of the most sophisticated 2D games ever designed,
The Phantom Hourglass for the Nintendo DS uses what amounts to just a simple point-and-click
Search Nedrilad ::

Custom Search