GML draw_set_alpha() sets everything on screen invisible {Solved}

M

MrSanfrinsisco

Guest
I'm trying to create a title screen for my game so it says "Can You Survive?" and then under it, it says "Press Enter To Start" and I want that part to fade in and out repeatably until they press enter. I know how to do it but for some reason "draw_set_alpha(0);" sets the "Can You Survive?" part of the title screen invisible. And no they are not the same object. The "Can You Survive?" is a separate object.
 

rIKmAN

Member
I'm trying to create a title screen for my game so it says "Can You Survive?" and then under it, it says "Press Enter To Start" and I want that part to fade in and out repeatably until they press enter. I know how to do it but for some reason "draw_set_alpha(0);" sets the "Can You Survive?" part of the title screen invisible. And no they are not the same object. The "Can You Survive?" is a separate object.
draw_set_alpha affects global alpha (ie. all drawing functions).

Set it back after you draw your "Press enter" text, or set it before you draw your "Can you survive?" text.
 
M

MrSanfrinsisco

Guest
draw_set_alpha affects global alpha (ie. all drawing functions).

Set it back after you draw your "Press enter" text, or set it before you draw your "Can you survive?" text.
That would actually make the "Can You Survive?" text fade in and out too because I'm going to constantly be changing the alpha so it will fade in and out forever. Is there a way I can just get that specific object and change that alpha?
 

rIKmAN

Member
That would actually make the "Can You Survive?" text fade in and out too because I'm going to constantly be changing the alpha so it will fade in and out forever. Is there a way I can just get that specific object and change that alpha?
No it won't.

Set it to 1 before you draw "Can you Survive" text, then set it to whatever your fade alpha value is before you draw "Press Enter".

Code:
draw_set_alpha(1.0)
draw_text(10, 10, "Can You Survive?"
...
...
...
draw_set_alpha(fade_value)
draw_text(10, 200, "Press Enter")
 
M

MrSanfrinsisco

Guest
No it won't.

Set it to 1 before you draw "Can you Survive" text, then set it to whatever your fade alpha value is before you draw "Press Enter".

Code:
draw_set_alpha(1.0)
draw_text(10, 10, "Can You Survive?"
...
...
...
draw_set_alpha(fade_value)
draw_text(10, 200, "Press Enter")
Oh, I'm not drawing the text "Can You Survive?". I created that text in ms paint and has a sprite set to it. There is no drawing for that text
 
L

Laurent57

Guest
So don't use draw_set_alpha but the alpha in draw_sprite
 

K3fka

Member
Should really be a non-issue if you just set the alpha before and after drawing the text. Borrowing from rIKmAN's code:

Code:
draw_set_alpha(fade_value);
draw_text(10, 200, "Press Enter");
draw_set_alpha(1);
 
M

MrSanfrinsisco

Guest
_ext of course
Alright that worked perfectly thank you! Now I've come across another problem (I'm very new at GML so I apologize).
Code:
draw_set_alpha(draw_get_alpha()+0.02);
This line of code isn't increasing the alpha of the text so now the text just stays gone
 
L

Laurent57

Guest
Well, do you still use a sprite or the function draw_text? Could you show or explain what contain your different events?
 

rIKmAN

Member
Alright that worked perfectly thank you! Now I've come across another problem (I'm very new at GML so I apologize).
Code:
draw_set_alpha(draw_get_alpha()+0.02);
This line of code isn't increasing the alpha of the text so now the text just stays gone
Post your full code.
 
M

MrSanfrinsisco

Guest
Well, do you still use a sprite or the function draw_text? Could you show or explain what contain your different events?
Post your full code.
Create Event
Code:
draw_set_alpha(1);
Step Event
Code:
if (draw_get_alpha() <= 0) {
    draw_set_alpha(draw_get_alpha()+0.02);
} else {
    draw_set_alpha(draw_get_alpha()-0.02);
}
Draw Event
Code:
cw = room_width;
ch = room_height;

cw = cw/2-250
ch = ch/2- 90

draw_sprite_ext(spr_titleScreen, -1, obj_titleScreen.x, obj_titleScreen.y, 
                                                    image_xscale, image_yscale, 0, c_white, 1);
draw_set_font(fnt_pressEtner);
draw_text(cw, ch, "Press Enter To Begin")
 
You have to keep in mind that code does not assume user intentions, and functions line by line. If you look at your Step event, it will increase the alpha by 0.02 if it's originally at 0, but upon the next frame when the alpha is checked, it no longer is at 0, so the else segment fires off instead, subtracting 0.02 and resetting the alpha to 0.

Create variables for both the current alpha and the target alpha and use this in the Step event instead. Use the alpha variable in draw_set_alpha(), change alpha_target whenever you like and you'll get a smooth transition.

alpha = min(alpha+0.02,max(alpha_target,alpha-0.02));
 
E

Ephemeral

Guest
Step Event
Well there's your problem. That is not how or where those functions are designed to be used. They should only ever be used in Draw events, never in the Step event, because the step events of ALL objects complete BEFORE any object's Draw event, so EVERYTHING will be affected, and inconsistently at that.

Set a variable, say, opacity = 0;, and another variable fade_in = true; in your create event, then:

Step Event:
Code:
if (fade_in)
{
    opacity += 0.02;
    if (opacity >= 1) fade_in = false;
} else {
    opacity -= 0.02;
    if (opacity <= 0) fade_in = true;
}
Draw Event:
Code:
draw_set_alpha(opacity);
draw_text(cw, ch, "Press Enter To Begin");
draw_set_alpha(1);
 
M

MrSanfrinsisco

Guest
Well there's your problem. That is not how or where those functions are designed to be used. They should only ever be used in Draw events, never in the Step event, because the step events of ALL objects complete BEFORE any object's Draw event, so EVERYTHING will be affected, and inconsistently at that.

Set a variable, say, opacity = 0;, and another variable fade_in = true; in your create event, then:

Step Event:
Code:
if (fade_in)
{
    opacity += 0.02;
    if (opacity >= 1) fade_in = false;
} else {
    opacity -= 0.02;
    if (opacity <= 0) fade_in = true;
}
Draw Event:
Code:
draw_set_alpha(opacity);
draw_text(cw, ch, "Press Enter To Begin");
draw_set_alpha(1);
Okay that actually makes way more sense. As a newbie game maker I very much appreciate that. It also fixed a couple of other problems I was having. For some reason if I hit enter on the title screen it would spawn my character but I would be invisible when I moved to the right and if I was invisible for too long the game would end. But when I put the game room before the title screen room that wouldn't happen. Now that doesn't happen and the game starts normally. Thank you so much!
 
Top