Legacy GM Setting Background Index Via the Draw Function

Odolwa

Member
I want to use the 'draw_background_ext' function to define my background sprite, but I don't seem to have the option to set the index without it operating by the values set in the Room Editor Backgrounds Tab. For instance:

Draw Begin Event:
Code:
 background_index[2] = bgr_1;
draw_background_ext(bgr_1, view_xview[0], view_yview[0], 1, 1, 0, c_white, 1);
With the above code, the first line draws the background sprite according to the values I set in the Room Editor at index 2, whereas the second line is drawing a second version of the same sprite behind another background I've set at index 0. What do I need to do to have the background drawn via the function be moved forward from 'background_index[0]' to 'background_index[2]'? Thank you.
 

obscene

Member
Can't follow your thought process at all here, but drawing a background and setting a background index are not the same thing at all.

Drawing a background is like drawing a sprite. The point in time where it is drawn depends on the depth of the instance doing the drawing.

Setting a background index will cause GM to automatically draw it before any of the instances do their drawing as long as background_visible[index] is true.
 
Last edited:

Odolwa

Member
Thanks for responding, Obscene. If I were to use the Draw event to draw multiple backgrounds to different depths/layers in a given room would I need to have separate instances for each one, or can one instance handle multiple background depths?
 

obscene

Member
First, an instance cannot draw to multiple depths. An instance only draws to it's own depth. You change the depth of an instance to change when it draws.

Second, an instance cannot draw to a background depth. Gamemaker draws backgrounds using built-in mechanisms. You only have the ability to set what those backgrounds are through background_index.

Typically you would set backgrounds in the room editor, so what are you trying to do beyond that?
 

Odolwa

Member
I came across some code a while back to simulate a torchlight effect. It basically entails creating a sprite which represents a torch with a glow effect around it and then using an object's Draw event to draw that sprite onto a surface which has been slightly darkened to create a shadowy effect. The end result is that the sprite will reveal the brighter colours behind the shadowy surface, thus giving the impression of a light.
The problem I have is that I want to do this with a background sprite, but I can't figure out how to draw the background onto the surface like I described above without compromising its position in the background index, i.e. the background sprite will appear in front (or behind) all the other backgrounds, but not at the index I actually want it at: 'background_index[2]'.
Can this be done?
 

obscene

Member
Yeah. So in order to do this you would need to have an object with a very high depth manually drawing all your background images instead of letting GM do it. (Disable their visiblity in the room editor so they don't draw twice and waste GPU time.) Any code you want to affect the drawing would need to be done at that time, ie, draw your backgrounds to a surface and apply your lighting. By the time you are drawing the torch, it's too late.

I have a script that draws backgrounds that you could probably start from...

Code:
for (var b=0; b<8; b+=1)
    {
    if (background_index[b]>=0)
        {
        if (background_tiled[b]==true) draw_sprite_tiled_ext(background_index[b],0,background_x[b],background_y[b],1,1,c_white,background_alpha[b]);
        else draw_sprite_ext(background_index[b],0,background_x[b],background_y[b],1,1,c_white,c_white,background_alpha[b]);
        }

    }
I did this in GMS2 to simulate backgrounds, not 100% if I remembered all the parameters for it to match up in GMS1. I guess you'd need to replace the draw_sprite functions with draw_backgrounds ones.
 

Odolwa

Member
Thanks for the script. Where the line reads as:
Code:
if (background_tiled[b] == true)
    draw_sprite_tiled_ext(background_index[b], 0, background_x[b], background_y[b], 1, 1, c_white, background_alpha[b]);
is there any way to have the code tile either vertically or horizontally, rather than both?
 

obscene

Member
Unfortunately not. GM's built-in backgrounds can be set to individually background_htiled[ ] or background_vtiled[ ] but when drawing them yourself you lose that function unless you want to use a textured primitive.
 
Top