Game Development Reference
In-Depth Information
1:
{
2:
if ( image_index == 2 ) event_user(0);
3:
image_index = 1;
4:
}
User events are a special kind of event which are only executed when we (the user)
explicitly tell Game Maker to do so. The name is a little confusing as in this case “user”
means “the programmer” of the game, and is nothing to do with the player.
This script executes user event 0 only if the button was already pressed for this
instance (as indicated by the value of
image_index
). This excludes the situation where
the mouse button is released over the button, but was initially pressed somewhere else
on the screen. Line 3 sets the button back to its highlighted state.
8.
Create four objects
obj_button_help
,
obj_button_options
,
obj_button_quit
, and
obj_button_start
, and set the sprites to
spr_button_help
,
spr_button_options
,
spr_button_quit
, and
spr_button_start
respectively. For each object, set the
Parent
to
obj_button
.
9.
For each object, add an
Other
,
User Defined
,
User 0
event. This event describes what
the button does once it is pressed. For our example, we have made
obj_button_help
open the game information and
obj_button_quit
end the game. Note that by using the
parent object, we define the button behavior once for all our buttons, but we made
each button have its own sprite and its own specific action using the user event.
10.
Finally, place instances of
obj_button_help
,
obj_button_options
,
obj_button_quit
,
and
obj_button_start
somewhere in the test room.
Result:
Reference/Result/fancy_buttons.gmk
Four- and Eight-Way Movement
Having reached this far in the topic, controls for moving the player around in four directions
should hardly be difficult for you. You would just create an event for each key and set sprite and
speed accordingly. However, sometimes (see for example Grid Movement), it can be more
convenient to script everything related to player movement in a single event. We'll show you how
to do this for a simple top-down game, where our explorer's movement is limited by a maze of
walls.
Start with:
Reference/Framework/explorer2.gmk
Creating Four-Way Movement
1.
Create a new object
obj_wall
and set the
Sprite
to
spr_wall
. Note that the framework
file already contains the sprites for this feature.
2.
Create a new object called
obj_explorer
. You may give the object any of the explorer
sprites if you want, but we'll let the object change sprites on its own.
Add a
Create
event and include a
Set Variable
action with
Variable
image_speed
and
Value
0
.
3.
Search WWH ::
Custom Search