Draw Background Tiled

draw_background_tiled - draws a background image, tiled to fill the room.

Syntax

draw_background_tiled ( back, x, y );

  • back - background that the programmer has set up in the background resources such as background0
  • x - x coordinate in the room
  • y - y coordinate in the room

Explanation

draw_background_tiled() draws a background at position (x,y) in the room during run time and tiles it to fill the entire room. The background image is defined in the background resources by the programmer.

Examples

Seasons Change

By creating a background of each season that you wish to depict, you would be able to change the seasons by changing the background. In a room where the image was pretty much all white snow or all green grass one could tile that image to fill the entire room. Keep in mind that this only effects the background and further coding would need to be done if wanting to change the sprite images for the objects to reflect the season. The following would be placed into a draw event of an object and would need a background that was defined as summer_grass_bkgrnd.

draw_background_tiled(summer_grass_bkgrnd,0,0);

Fields of Grey

Takes a grey default room and tiles the background with a grass gif that I have on my computer.

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);

Note: Not exactly sure what the purpose of defining x and y coordinates are as my experience shows that 0,0 produces the same results as 100,100. The entire room is tiled with the background.

Related Pages

  • Link

Backlinks