GameMaker [Solved + Shared Final Code] Changing Background Color of Current Room

B

bc1187

Guest
Here's my code:

Code:
if(day){

    draw_text(10,10,"It's currently daytime");
    //I want to set background color to something here

}else{

    draw_text(10,10,"It's currently nighttime");
    //I want to set background color to something here

};
In the commented sections, I want to be able to manipulate the background hex color of the room where this object is placed.

What syntax/code is needed to do this? Google searches were giving conflicted/dated info, so any help is appreciated!
 

hogwater

Member
background_color

Check the manual, as you also want to make sure that you are showing the bg color. This is for 1.4, Studio 2 may or may not be different.
 
B

bc1187

Guest
background_color

Check the manual, as you also want to make sure that you are showing the bg color. This is for 1.4, Studio 2 may or may not be different.
This didn't work. Getting a compile error with background_color:

Code:
if(day){

    draw_text(10,10,"It's currently daytime");
    background_color(c_red);

}else{

    draw_text(10,10,"It's currently nighttime");
    //I want to set background color to something here

};
 
B

bc1187

Guest
background_color = c_red

Or background_colour, since GM is chiefly British. o_O
First off, I'm an idiot, lol. Totally had that code written wrong.

Okay, so, now with the code CORRECTLY written, no compile errors but code is not changing the background color (or colour - tried both)

Code:
if(day){

    draw_text(10,10,"It's currently daytime");
    background_color = c_red;

}else{

    draw_text(10,10,"It's currently nighttime");
    //I want to set background color to something here

};
edit: and I can confirm the code is working properly to where day = true in some circumstances as the draw_text is functioning correclty
 

Perseus

Not Medusa
Forum Staff
Moderator
That's so because there's no background_colour in GMS2; it is now obsolete on account of major changes to how backgrounds work in that version. AFAIK it's not possible to change background colour via code currently. But you can configure the room editor to have white as the default background colour (or use a sprite for texture effects) then use layer_background_blend() to "tint" it accordingly.
 
B

bc1187

Guest
That's so because there's no background_colour in GMS2; it is now obsolete on account of major changes to how backgrounds work in that version. AFAIK it's not possible to change background colour via code currently. But you can configure the room editor to have white as the default background colour (or use a sprite for texture effects) then use layer_background_blend() to "tint" it accordingly.
Following up - thank you!!! Was finally able to get the code working with this function.

Case closed here. Sharing the final code that worked in case others need it:

Code:
lay_id = layer_get_id("Background");
back_id = layer_background_get_id(lay_id);

if(day){

    draw_text(10,10,"It's currently daytime");
    layer_background_blend(back_id, $009900);

}else{

    draw_text(10,10,"It's currently nighttime");
    layer_background_blend(back_id, $001E00);

};
Bit random, but is there a way to add a "blend" so it fades between these changes? Though this is certainly how "feature creep" starts, I'm just a bit curious.
 

Pawel

Member
Bit random, but is there a way to add a "blend" so it fades between these changes?
You can use merge_color(col1, col2, amount) function which will create color between col1 and col2 depending of the amount value.
For more complicated effects you can use shader which will change colors of all elements in the room that need to change. You can easily find such shaders in the marketplace.
 

TibiSoft

Member
Following up - thank you!!! Was finally able to get the code working with this function.

Case closed here. Sharing the final code that worked in case others need it:

Code:
lay_id = layer_get_id("Background");
back_id = layer_background_get_id(lay_id);

if(day){

    draw_text(10,10,"It's currently daytime");
    layer_background_blend(back_id, $009900);

}else{

    draw_text(10,10,"It's currently nighttime");
    layer_background_blend(back_id, $001E00);

};
Bit random, but is there a way to add a "blend" so it fades between these changes? Though this is certainly how "feature creep" starts, I'm just a bit curious.
Thanks, it is working well. :)
 
Top