Game Development Reference
In-Depth Information
This now helps to prevent fighting between the two states by essentially making ice
take priority over land, as it will only switch back to the land state when there is a
platform below Flynn, and there is no ice.
So try walking Flynn around the test level now. Hopefully, you can see what we mean about
a constant movement rate and fixed movement distance. Nonetheless, the animated effect of
the character is much more believable and visually consistent as a result. We can't make all our
transitions between animations as smooth as this, but as walking is the most common one, it
has the most effect on the overall impression of the game.
Over the Top
Next, we're going to address climbing animations including an animation for when Flynn
climbs to the top of a wall and pulls himself onto the surface above. Not only is this a particularly
hard movement to animate, but it can also be difficult to integrate it within the game in a way
that makes it look like the character is physically interacting with the landscape. Fortunately,
the simple solutions are often the best, so we'll just use an animation that has all the movement
as part of the animation (see Figure 12-3). This kind of animation is set up to make it look as if
Flynn is moving in the game world when he actually isn't (his coordinates and bounding box
will remain on the side of the wall). As a result, we will need to quickly move the Flynn instance
into the new position at the end of the animation so that it appears as if his climb is one
con ti n uous se que n ce .
Adjusting Flynn's Climbing Mechanic
1.
Create a new constant called
FSTATE_CLIMB_TOP
set to a value of
7
.
2.
Create two new sprite resources called
spr_flynn_climb_top_right
and
spr_flynn_climb_top_left
using the appropriate files from the
Chapter12/Resources/Sprites/Flynn
directory on the CD.
3.
Modify the mask of
spr_flynn_climb_top_right
to use a
Rectangle
Shape
and
Manual
Bounding Box
set to
Left
=
48
,
Right
=
80
,
Top
=
144
, and
Bottom
=
298
, with an
Origin
of
X
=
64
,
Y
=
208
.
4.
Modify the mask of
spr_flynn_climb_top_left
to also use a
Rectangle
Shape
and
Manual
Bounding Box
, but set to
Left
=
128
,
Right
=
160
,
Top
=
144
,
Bottom
=
298
, and with
an
Origin
of
X
=
144
,
Y
=
208
.
There are two things worth observing here, so take a careful look at the sprites and
animations. As already discussed, the sprites include Flynn's movement on top of the wall as
part of the animation, and that makes them larger than all the other sprites. Flynn's first
subimage is offset to one side of the sprite to make room for the animation and the sprite's
Origin
has been offset to match (set just above his knee in the first subimage). Secondly, Flynn's
bounding box remains in the same position throughout the animation, which is something we'll
need to consider later.
Now, edit the
Draw
event of
obj_flynn
and add a new case for drawing the climb top
sprite within the block for
FACE_RIGHT
:
5.
case FSTATE_CLIMB_TOP: sprite_index = spr_flynn_climb_top_right; break;
and then
FACE_LEFT
:
case FSTATE_CLIMB_TOP: sprite_index = spr_flynn_climb_top_left; break;
Search WWH ::
Custom Search