Game Development Reference
In-Depth Information
Including Archie's Movement as Part of the Camera Focus
1.
Edit the
Step
event of
obj_focus
and replace the two lines that initially set
targetx
and
targety
with the following lines of code:
1:
if( obj_parrot.state == ASTATE_FOLLOW )
2:
{
3:
targetx = obj_flynn.x;
4:
targety = obj_flynn.y;
5:
}
6:
else
7:
{
8:
targetx = (obj_flynn.x*0.75) + (obj_parrot.x*0.25) ;
9:
targety = (obj_flynn.y*0.75) + (obj_parrot.y*0.25);
10:
}
Line 1 checks to see if Archie is in the follow state, as there's no point taking his
position into account if he's not doing something interesting. If he is just following,
then lines 3 and 4 set the target position in the usual way, but otherwise lines 8 and 9
set the target position based on 75% of Flynn's position and 25% of Archie's. This gives
a nice compromise that makes it impossible for Flynn to disappear out of view, but
allows the camera to follow Archie on his travels.
Try out the final camera again and see what difference it makes to moving Archie around
the level. You should now be able to move Archie an entire screen width away from Flynn,
before he disappears out of view (see Figure 12-8). A custom camera can add a lot to your game
and this is one way to quickly achieve it. You could of course adjust the position of the view
directly using the
view_xview[0]
and
view_yview[0]
variables without relying on Game Maker
to follow a particular object if you want to take direct control of everything.
If you have any problems with your version, then you can check it against the file
shadows6.gmk
in the
Chapter12/Games
directory on the CD.
Search WWH ::
Custom Search