Designing Games with GameMaker
Views
As you should know you can define up to eight different views when designing rooms. A view is defined by its view area in the room and its viewport on the screen (or to be precise in the drawing region within the window). Using views you can show different parts of the room at different places on the screen. Also, you can make sure that a particular object always stays visible.You can control the views from within code. You can make views visible and invisible and change the place or size of the views in the drawing region or the position and size of the view in the room (which is in particular useful when you indicate no object to be visible). You can change the size of the horizontal and vertical border around the visible object, and you can indicate which object must remain visible in the views. The latter is very important when the important object changes during the game. For example, you might change the main character object based on its current status. Unfortunately, this does mean that it is no longer the object that must remain visible. This can be remedied by one line of code in the creation event of all the possible main objects (assuming this must happen in the first view):
{ view_object[0] = object_index; }
The following variables exist that influence the view. All, except the first two are arrays ranging from 0 (the first view) to 7 (the last view).
view_enabled Whether views are enabled or not.
view_current* The currently drawn view (0-7). Use this only in the drawing event. You can for example check this variable to draw certain things in only one view. Variable cannot be changed.
view_visible[0..7] Whether the particular view is visible on the screen.view_xview[0..7] X position of the view in the room.
view_yview[0..7] Y position of the view in the room.
view_wview[0..7] Width of the view in the room.
view_hview[0..7] Height of the view in the room.
view_xport[0..7] X-position of the viewport in the drawing region.
view_yport[0..7] Y-position of the viewport in the drawing region.
view_wport[0..7] Width of the viewport in the drawing region.
view_hport[0..7] Height of the viewport in the drawing region.
view_angle[0..7] Rotation angle used for the view in the room (counter-clockwise in degrees).
view_hborder[0..7] Size of horizontal border around the visible object (in pixels).
view_vborder[0..7] Size of vertical border around visible object (in pixels).
view_hspeed[0..7] Maximal horizontal speed of the view.
view_vspeed[0..7] Maximal vertical speed of the view.
view_object[0..7] Object whose instance must remain visible in the view. If there are multiple instances of this object only the first one is followed. You can also assign an instance id to this variable. In that case the particular instance is followed.
Note that the size of the image on the screen is decided based on the visible views at the beginning of the room. If you change views during the game, they might no longer fit on the screen. The screen size though is not adapted automatically. So if you need this you have to do it yourself, using the following functions:
window_set_region_size(w,h,adaptwindow) Set the width and height of the drawing region in the window. adaptwindow indicates whether the window size must be adapted if the region does not fit in. The window size will always be adapted if you use fixed scaling. (See the function window_set_region_scale().)
window_get_region_width() Returns the current width of the drawing region.
window_get_region_height() Returns the current height of the drawing region.
In a game you often need the position of the mouse cursor. Normally you use for this the variables mouse_x and mouse_y. When there are multiple views, these variables give the mouse position with respect to the view the mouse is in. Sometimes though, you might need the mouse position with respect to a particular view, also when it is outside that view. For this the following functions exist.
window_view_mouse_get_x(id) Returns the x-coordinate of the mouse with respect to the view with index id.
window_view_mouse_get_y(id) Returns the y-coordinate of the mouse with respect to the view with index id.
window_view_mouse_set(id,x,y) Sets the position of the mouse with respect to the view with index id.
window_views_mouse_get_x() Returns the x-coordinate of the mouse with respect to the view it is in (same as mouse_x).
window_views_mouse_get_y() Returns the y-coordinate of the mouse with respect to the view it is in (same as mouse_y).
window_views_mouse_set(x,y) Sets the position of the mouse with respect to the first view that is visible.
Alternative versions
Also available in: None
Download helpfile