Backgrounds are another form of image asset that you can use in
GameMaker: Studio, and are split into two general
categories: background images and tilesets. Background images are
generally the large, static images that are used to form the back
of a room, with all other things being drawn over them, although
they can have other uses, while tilesets are background images that
are "cut up" into smaller pieces and used to add low cost graphical
images to a level. For example, in a platform game you may have
only one single floor object and then use a series of background
tiles to hide them and give each an individual "look".
The following global variables are built in to GameMaker: Studio and can be used to get information about a background asset as it is currently used within a room. Most of these variables can be set as well as read and so can be used to change the way backgrounds are displayed within the room, but any changes that they make to the background are not permanent and will be reset if the player leaves and enters the room again, or the game is restarted (unless the room is persistent). Please note that these all affect the current room only, but if you should need to set any of these values for another room you should be using the function room_set_background().
- background_index[0..7]
- background_visible[0..7]
- background_alpha[0..7]
- background_blend[0..7]
- background_x[0..7]
- background_y[0..7]
- background_colour
- background_showcolour
- background_foreground[0..7]
- background_hspeed[0..7]
- background_vspeed[0..7]
- background_htiled[0..7]
- background_vtiled[0..7]
- background_width[0..7]
- background_height[0..7]
- background_xscale[0..7]
- background_yscale[0..7]
The following functions can be used to get information about a background asset. Please note that these functions get the information from the base background (ie. the background asset) and not from the background as it is being used in a room. For information on backgrounds that are being used in a specific room, see the section on "Background Variables" above.
The functions below are all related to changing the sprite asset (resource) itself. This means that the majority of these functions will affect all instances that reference the sprite being changed, it also means that you must take great care to ensure that a sprite exists before referencing it, or to make sure it is not being referenced before changing it.
- background_exists
- background_add
- background_replace
- background_duplicate
- background_assign
- background_create_colour
- background_create_gradient
- background_create_from_surface
- background_set_alpha_from_background
- background_save
- background_delete
- background_flush
- background_flush_multi
- background_prefetch
- background_prefetch_multi
The following section has all the different functions and variables that are related to background images when they are used to create tiles in a room: