background_add(fname, removeback, smooth);
Argument | Description |
---|---|
fname | The name (string) of the file to added. |
removeback | Indicates whether to make all pixels with the selected colour (left-bottom pixel) transparent. |
smooth | Indicates whether to smooth the edges if transparent. |
Returns: Real
With this function you can add an image as a background, loading
it from an external source where the image file to be loaded should
always be *.png format. The function returns the
new background index which must then be used in all further codes
that relate to this background. If you use this function with HTML5
or are getting an image from an URL, this function will also
generate an asynchronous event. See
Advanced Use - More About Async Events for more
information.
Setting the "removeback" argument to true will remove a
colour from the background, by checking the bottom left
pixel of the defined area for the colour there and then using that
as the colour to be removed.
If you choose the "removeback" option, you may also want
GameMaker: Studio to smooth the edges of the background by
setting the "smooth" argument to true. All this does is
create a semi-transparent border around the edges of the background
after it has had its background removed.
It is worth noting that when you load a background into
GameMaker: Studio in this way you must remember to remove it
again (with background_delete) when no
longer needed, otherwise there is risk of a memory leak which will
slow down and eventually crash your game.
NOTE: Depending on the target platform that is chosen you
are limited as to where you can save and load files from. See
Reference - Files
for more information.
NOTE: You should be aware that if you are using this
function in your HTML5 target game to load resources from an
external server, then, due to XSS protection in browsers, attempts
to load resources from across domains can be blocked and may appear
to return blank results.
bck = background_add("Sky_5.png");
The above code loads a background into the game and stores its index in the variable "bck".