• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [SOLVED] draw_set_alpha not effecting triangles

T

Tony Lukasavage

Guest
Hey, first post so forgive if I miss any etiquette.

I'm having trouble getting draw_set_alpha to behave as expected. My draw_set_alpha calls do not make the triangles disappear when triangle_visible equals zero (on a repeating timer in the step event). I know for a fact that the value is set to zero during my game for 2 reasons. 1, I checked with a show_debug_message() call, but more importantly, if I don't uncomment that last line that resets the alpha to 1, then other parts of my game will flicker in and out of visibility, just like I would expect these triangles to do. Just to give all details, the other parts of my game that are flickering are sprites, while the triangles are obviously drawn.

One additional note is that if the initial value of triangle_visible is zero, then the triangles will be invisible for the first iteration of the timer. After the first time it is made visible though, it stays visible forever, even though as stated earlier, other parts of my game will continue to flicker in and out of visibility. It's as though once it is drawn once it will never disappear.

I'm new, so I'm hoping I'm missing something simple.

Code:
draw_set_alpha(0.66 * triangle_visible);
draw_set_color(c_black);
draw_triangle(
    x + shadow_offset,
    y + shadow_offset,
    x + size + shadow_offset,
    y + shadow_offset,
    x + size/2 + shadow_offset,
    y + size + shadow_offset,
    false
);
    
draw_set_alpha(1 * triangle_visible);
draw_set_color(color);
draw_triangle(
    x,
    y,
    x + size,
    y ,
    x + size/2,
    y + size,
    false
);

//draw_set_alpha(1);
Not sure if it's necessary but here's the step event that changes the triangle_visible variable, that I am certain is working due to the behavior of the rest of the game.

Code:
timer++;

if (triangle_visible == 1 && timer > 40) {
    triangle_visible = 0;   
    timer = 0;
} else if (triangle_visible == 0 && timer > 20) {
    triangle_visible = 1;
    timer = 0;
}
and here's the create event where the variables are set

Code:
size = 20;
color = c_white;
shadow_offset = 3;
triangle_visible = 1;
x = 0;
y= 0;
timer = 0;
 

marasovec

Member
I would make if triangle_visible is 0 just don't draw it
Code:
if (triangle_visible == 1)
{
    draw_set_alpha(0.66);
    draw_set_color(c_black);
    draw_triangle(
       x + shadow_offset,
       y + shadow_offset,
       x + size + shadow_offset,
       y + shadow_offset,
       x + size/2 + shadow_offset,
       y + size + shadow_offset,
        false
    );
  
    draw_set_alpha(1);
    draw_set_color(color);
    draw_triangle(
       x,
       y,
       x + size,
       y ,
       x + size/2,
       y + size,
      false
    );
}
 
T

Tony Lukasavage

Guest
@marasovec great idea, and even better performance. That said, I'd like to understand why this doesn't work as expected. For example, another way I considering presenting this triangle is as fading in and out. If I can't change the alpha as expected, that becomes impossible. So I'd still be left with the same problem.

UPDATE: I tried it and it's still not making the triangles disappear! I'm seeing that the triangle_visible value is changing and impacting other parts of the game, but the triangles remain. Is there something basic I'm missing about drawing in GMS2? Do I need to clear the drawing on each frame or something? It's just like once they are drawn, they are there forever.

UPDATE2: I may have figured this out. It may be related to my newb misunderstanding of object composition in GML. Will report back soon.
 
Last edited by a moderator:
T

Tony Lukasavage

Guest
@marasovec I appreciate the help so far, but your last post isn't true. GML's grammar does a fine job handling order of evaluation and doing math within the function invocation works just fine. I don't think "pure number" is really a thing. Sorry if I'm coming off like a know-it-all, but I'm a dev by trade.
 

marasovec

Member
@marasovec I appreciate the help so far, but your last post isn't true. GML's grammar does a fine job handling order of evaluation and doing math within the function invocation works just fine. I don't think "pure number" is really a thing. Sorry if I'm coming off like a know-it-all, but I'm a dev by trade.
Oh wow it really works?? I tried it a long time ago and I think it never worked for me. Thanks for correcting me
 

Ido-f

Member
Do you have a background layer? If you don't then you don't have anything to 'clear' and reset the screen with, so anything drawn in previous steps will just stay there.
 
T

Tony Lukasavage

Guest
haha, I got it. The issue was that I'm learning how to compose complex objects out of other objects. I was instantiating the triangle object in a draw event event instead of the create event. It was instantiating a new triangle on every frame, therefore making it appear to always be on the screen. Thanks for being a sounding board though @marasovec, I'm sure just talking through it helped.
 
Top