Game Development Reference
In-Depth Information
Game Maker also includes a number of special object names that you can use to refer to
different objects in the game:
•
other
is an object that is used to refer to the other instance involved in a collision
event. So
other.x
is the x position of the other object involved in a collision.
all
is an object that refers to all instances, so setting
all.visible
to
0
would make all
instances of all objects invisible.
•
•
global
is an object used to refer to global variables that you create yourself.
Global Variables
You can also create
global variables
, which are common to all objects and instances in the game.
These are useful for storing values that relate to the overall state of the game, such as the current
player's name, or time playing the game. When you use a global variable of your own, you need to
put the word
global
and a period (full-stop) in front of the variable name (for example,
global.player_name
). If you leave off the
global
part, then Game Maker will automatically assume
you are referring to a local variable instead.
However, there are also a number of built-in global variables that do not require the use of
the
global
object to access them. This can cause problems if you try and create local variables
with the same name, so it's best to be aware of these so that you can choose different names:
•
score
is the global score value (as used by the actions on the
score
tab).
lives
is the global lives value (as used by the actions on the
score
tab).
•
health
is the global health value (as used by the actions on the
score
tab).
•
mouse_x
is the current x position of the mouse cursor in the room.
•
mouse_y
is the current y position of the mouse cursor in the room.
•
room_caption
is the caption shown in the window title bar.
•
room_width
is the width of the current room in pixels.
•
•
room_height
is the height of the current room in pixels.
Coordinates and Angles
If you want to position something in your room using actions (rather than the Room Editor),
then you need to consider how Game Maker's coordinate system works. Traditionally,
coordinates on computer screens are calculated slightly differently from how they are taught in
school. As you might expect, the x-axis starts on the left-hand side of the screen with a value of
zero and increases as you move horzontally to the right. However, the y-axis starts at the top of
the screen with a value of zero and increases as you move vertically down (see Figure 1-3). This
means that the origin of each room (x=0,y=0) is in the top left, rather than the bottom left and the
y-axis is probably the other way from how you might have expected as well. Nonetheless, so long
as you can remember that an increase in y moves something down the screen, then you won't go
too far wrong.
Search WWH ::
Custom Search