Game Development Reference
In-Depth Information
Instances and Objects
Objects are the programmable elements of your game and their behavior is directly determined
by the
events
and
actions
that
you choose to give them. However, there is an important
distinction to be made between the
object
resources
,
which define the general behavior of objects,
and the individual
object
instances
,
which occupy your game world. Once you have defined the
behavior of an object resource, then you can place any number of instances of that object in your
game. All these instances will behave in the same way (because they follow the same events and
actions), but each has its own variables (position, speed, direction, and so forth) that are unique
to that instance. If you like, you can think of object resources as being like jelly molds, and
instances as the jellies you make with them. You only need one mold to make any number of
jellies that have the same basic structure (see Figure 1-2).
Figure 1-2.
Object resources are like jelly molds and you can use them to create any number of object
instances
Variables
A variable is a general programming term for something that can store information. In Game
Maker,
variables can either store a number (for example,
3
,
-12
,
151.33
) or some text (for
example,
demons
don't
like
dragons
). You use variables in Game Maker
to store all the unique
information about individual instances, such as their position on the screen, or their speed. So if
you create a new
power
variable in the
Create
event of a dragon object, then every dragon object
will have this variable, but each instance can have its own different value for
power
. It's also worth
noting that you must assign variables a value (using a
Set Variable
action, for example) before
you can use them (with a
Test Variable
action); otherwise, Game Maker will produce an error.
Search WWH ::
Custom Search