Game Development Reference
In-Depth Information
Creating the Remaining State Objects
1.
Create a new object called
obj_pod_walking
. You can set its
Sprite
to be either
spr_pod_walk_left
or
spr_pod_walk_right
, as we will be selecting the correct sprite
manually in the
Create
event. Set its
Depth
value to
-1
so that it appears in front of
other objects.
2.
Create a new object called
obj_pod_jumping
. Set its
Sprite
to be either
spr_pod_jump_left
or
spr_pod_jump_right
and set its
Depth
to
-1
.
3.
Create a new object called
obj_pod_falling
. Set its
Sprite
to be either
spr_pod_fall_left
or
spr_pod_fall_right
and set its
Depth
to
-1
.
4.
Create a new object called
obj_pod_dying
. Set its
Sprite
to be either
spr_pod_jump_left
or
spr_pod_jump_right
and set its
Depth
to
-1
. The jump sprite shows Fishpod
spinning, so we will also use this as a dying animation played as he falls from the
screen.
There are now two state transitions that we need to handle for
obj_pod_standing
(see Figure
2-9). The first is to change into the walking state when the player presses the arrow keys and the
second is to change into the jumping state when the player presses the space bar. This will
require three separate events in total: two
Keyboard
events for the left and right arrow keys and
one
Key Press
event for the space bar. These are implemented as follows.
Adding Key Events to the Standing State Object
1.
Reopen the Object Properties for
obj_pod_standing
by double-clicking on it in the
resource list.
2.
Click on the
Add Event
button and select the
Keyboard <Left>
event. We are using a
Keyboard
event because we want Fishpod to keep walking when the player holds
down the arrow keys.
Include a
Set Variable
action (
control
tab) in the actions list. Type
facing
into
Variable
and
FACE_LEFT
into
Value
. We will use this to make sure that Fishpod faces left when
you press the left arrow key.
3.
4.
Include a
Change Instance
action (
main1
tab) in the actions list. Select
obj_pod_walking
from the
Change Into
menu and
yes
for
Perform Events
. This last
setting means that the
Create
event of
obj_pod_walking
will be called as part of the
change—the default is
not
to do so.
Repeat steps 2-4 using a
Keyboard <Right>
event and setting
facing
to
FACE_RIGHT
instead.
5.
6.
Click on the
Add Event
button and select a
Key Press <Space>
event. We are using a
Key Press
event here because we only want Fishpod to jump once for each press of the
space bar.
7.
Include a
Change Instance
action (
main1
tab) in the actions list. Select
obj_pod_jumping
from the
Change Into
menu and
yes
for
Perform Events
so that the
Create
event of
obj_pod_jumping
is called as part of the change.
That completes all the behaviors and transitions for the standing state object. We'll work on
the walking state object next, as this will take us closer to something we can actually try out. As
before, the
Create
event for the walking state object will set up the behavior of Fishpod in that
state and a number of additional events that handle the transitions to other states.
Search WWH ::
Custom Search