Background Exists

background_exists - checks whether a background with a specified index exists.

Syntax

background_exists ( ind );

  • ind - background index

Explanation

background_exists() checks if a background with a specified index exists and returns 0 if doesn't exist or 1 if does exist.

Examples

Fields of Grey

Loads a background image from a file and draws it on the screen.

Create an object which for this example I will leave as object0.

The Draw Event of object0 will check for the existence of the newback index. As such we will want to define it and initialize it in the Create Event.
In the Create Event of object0:

newback = 0;

If there is a file named grass.gif on the c: drive in the root directory then the following code will work. If there isn't, then please make sure that you place the correct filename's path in single quotes.
In the object0 Keyboard Event for <Space> key:

newback = background_add('C:\grass.gif',false,false,false);

As exciting as it is to load a background image from a file, if we don't draw it then the player will never see it. The following is one method of doing this. First it checks to make sure that the background exists and if it does then it will tile it.
In the object0 Draw Event:

if background_exists(newback) 
    then 
        draw_background_tiled(newback,0,0);

Related Pages

*background_index

Backlinks