Game Development Reference
In-Depth Information
1:
{
2:
if ( view_current == 0 )
3:
{
4:
draw_set_font(fnt_score);
5:
draw_set_color(c_white);
6:
draw_text(view_xview[0]+480,
7:
view_yview[0]+20,'Score: '+string(score));
8:
dx1 = view_xview[0]+view_xport[1];
9:
dy1 = view_yview[0]+view_yport[1];
10:
dx2 = dx1+view_wport[1];
11:
dy2 = dy1+view_hport[1];
12:
draw_rectangle(dx1-1,dy1-1,dx2+1,dy2+1,true);
13:
}
14:
}
This script takes some explaining. The entire room is redrawn once for each view,
which actually means that all draw events are executed twice: once for view 0 and once
for view 1. The variable
view_current
keeps track of which view is currently being
drawn. We check it in line 2 so we can draw the score only in view
0
(lines 4-7).
Lines 8-12 draw a rectangle around view 1, which must also be done in view 0. In
fact, just like the score, the rectangle must follow view 0 around (which, in turn, follows
the spaceship) to keep it on the screen. The variables
dx1
,
dy1
,
dx2
, and
dy2
are used to
calculate the positions in the room between which the rectangle must be drawn so that
it always appears in the top-left corner of view 0, which is our main view. Line 12
finally draws it, making it a pixel larger than view 1 on each side.
Result:
Reference/Result/mini_map1.gmk
You'll have noticed that making the room ten times smaller in the mini-map view doesn't
make it any easier to see what's going on in the mini-map. It sometimes makes sense to map only
a portion of the room that is only somewhat larger than what is actually shown in the main view.
Changing the Mini-Map to View Only Part of the Room
1.
Open
test_room
again, select the
views
tab, and click
View 1
. Because we're only going
to show part of the room, we'll have to make it follow the spaceship around. Set
Object
following
to
obj_spaceship
.
2.
First, let's decide how large the viewed area is. Once again, it is a good idea to set this
in proportion to the port of the view. To size things up, halve the values in
View in
room
to
800
for width and
600
for height. It shouldn't be any smaller than this, because
the main view is 640x480.
Let's try to center the spaceship in the mini-map view as well. Set
Hbor
to
400
and
Vbor
to
300
—this sets the horizontal and vertical borders around the spaceship to
exactly half the size of the view in the room set previously, which centers the spaceship
in the mini-map.
3.
Result:
Reference/Result/mini_map2.gmk
Search WWH ::
Custom Search