draw_rectangle() Problems with Transparency

I'm trying to make a textbox that appears when the mouse hovers over the object, and I'm drawing a rectangle as a backdrop for it. However, if the object is far enough to the right, I want to make it draw in the opposite direction, but when I do, it turns semi-transparent and draws behind other sprites in the room. I've been pulling my hair out for quite a while now, and I'm at a loss.


(the game involves progressing through different eras in history, and the colour of the rectangle needs to change based on what era the player is in, so that's where all the draw_set_colour() functions come from, and I know I'm calling the certain functions more than I need to, but this makes it more clear what I'm doing, at least I think)

In the Draw event, my original code was:
GML:
//Change colour based on era
if (menu.era == "m") || (menu.era == "r") draw_set_colour($466670);
if (menu.era == "i") draw_set_colour(c_gray);
if (menu.era == "mo") draw_set_colour(c_white);
if (menu.era == "f") draw_set_colour(c_black);

//Get textbox information
var effectsText = title+":\n"+desc+"\n"+effects;

//Draw textbox
draw_rectangle(
    mouse_x,
    mouse_y,
    mouse_x+string_width(effectsText)+8,
    mouse_y+string_height(effectsText)+8,
    false
);

//Get outline colour
if (menu.era == "m") || (menu.era == "r") draw_set_colour($1d2527);
if (menu.era == "i") draw_set_colour(c_dkgray); //Change this one...
if (menu.era == "mo") draw_set_colour(c_black);
if (menu.era == "f") draw_set_colour(c_white);

//Draw Outline
draw_rectangle(
    mouse_x,
    mouse_y,
    mouse_x+string_width(effectsText)+8,
    mouse_y+string_height(effectsText)+8,
    true
);

//Draw Information
draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_set_colour(c_black);
if (menu.era == "f") draw_set_colour(c_white);
draw_text(
    mouse_x+4,
    mouse_y+4,
    effectsText
);
This works perfectly fine. However, when I change it to this, adding only a simple check to see if it's over to the right far enough for me to want to draw the textbox right-aligned instead of left, the rectangle has all of the issues described previously:

GML:
//Change colour based on era
if (menu.era == "m") || (menu.era == "r") draw_set_colour($466670);
if (menu.era == "i") draw_set_colour(c_gray);
if (menu.era == "mo") draw_set_colour(c_white);
if (menu.era == "f") draw_set_colour(c_black);

//Get textbox information
var effectsText = title+":\n"+desc+"\n"+effects;

//Switch direction
if (x >= (room_width-256)/2) var dir = -1;
else dir = 1;

//Draw textbox
draw_rectangle(
    mouse_x,
    mouse_y,
    mouse_x+(string_width(effectsText)+8)*dir,
    mouse_y+string_height(effectsText)+8,
    false
);

//Get outline colour
if (menu.era == "m") || (menu.era == "r") draw_set_colour($1d2527);
if (menu.era == "i") draw_set_colour(c_dkgray); //Change this one...
if (menu.era == "mo") draw_set_colour(c_black);
if (menu.era == "f") draw_set_colour(c_white);

//Draw Outline
draw_rectangle(
    mouse_x,
    mouse_y,
    mouse_x+(string_width(effectsText)+8)*dir,
    mouse_y+string_height(effectsText)+8,
    true
);

//Draw Information
draw_set_halign(fa_left);
if (dir == -1) draw_set_halign(fa_right);
draw_set_valign(fa_top);
draw_set_colour(c_black);
if (menu.era == "f") draw_set_colour(c_white);
draw_text(
    mouse_x+4*dir,
    mouse_y+4,
    effectsText
);
I've tried cleaning the console, changing the order of the inputs, even going so far as to write separate draw_rectangle() functions like so:
GML:
if (dir == 1)
{
    draw_rectangle(
        mouse_x,
        mouse_y,
        mouse_x+(string_width(effectsText)+8),
        mouse_y+string_height(effectsText)+8,
        true
    );
}
else
{
    draw_rectangle(
        mouse_x-(string_width(effectsText)+8),
        mouse_y,
        mouse_x,
        mouse_y+string_height(effectsText)+8,
        true
    );
}
I'm not sure what's going on, but if anyone could shed some light on this, that would be really helpful.
 

FrostyCat

Member
Search your project for all calls to draw_set_alpha. For every one that sets the alpha away from 1, make sure there is another down the line setting the alpha back to 1. This is the same reason you set the font alignments back to left-top after setting it away to something else.
 
I even used draw_set_alpha(1) right before drawing the rectangles and it still didn't work. I can try messing around in the debugger a bit more, but I'm not sure why it would affect it in one case but not the other.
 
Top