SOLVED Issue with alpha and surfaces

I got an object obj_foo with the following Draw Event:
This code draws a blinking green square (scr_wave is a script that I created that create values following a cos signal)

And I got an objet obj_surf with the following Draw Event:

if surface_exists(surface) { //in create event : surface = noone;
    draw_clear_alpha(col_purpule, .97); //col_purple a a color that I defined in the create event

    with (obj_foo) event_perform(ev_draw, 0);

    draw_surface(surface, x1, y1);
} else {
    surface = surface_create(x2 - x1, y2 - y1);
The above codes are simplified, but here is the end result :
The surface created is the purple zone and I create the obj_foo at the four corners. Do not pay attention to the objects displayed at the top left, I just did not uncheck the visible option of these objects.
As you can the when the alpha of the obj_foo is low, the transparency makes the background appear directly and not the purple of my surface. How can I resolve this issue?
Thanks !


Just mess around with draw_enable_alphablend() at different times, or play with blend modes.

You don't need the pictures in that post, they weren't very helpful. lol
Thanks for answer ! I am moving forward in my problem, but I still have a small problem: It is not necessarily visible in the video, but the "background" is not 100% opaque, (its alpha is 96% ...) .The blendmode adding the alphas of my two components, it is clear that I thus obtain a total alpha always greater than 1. However, I do get the desired effect of "blinking" from my green square. So I would like to find a way to get by with its blendmodes by getting a constant alpha (which is the alpha of my surface, so here 96%). An idea? Thank you.

PS : Because I'm not sure I'm understandable, there is an image with the alpha of my surface lowered at 70% : You can see that the alpha of my squares is higher than the alpha of my surface


Friendly Tyrant
Forum Staff
Okay, when you have drawn everything to the surface, but BEFORE resetting the draw target call gpu_colourwriteenable(false, false, false, true) and then draw a solid black rectangle over the entire surface. After that call the same function again setteing everything to true, then reset the surface target to normal drawing again. This should correct the issue you are having with the surface alpha. So:


// Draw everything here

gpu_colourwriteenable(false, false, false, true);
draw_rectangle(0, 0, surf_width, surf_height, false);
gpu_colourwriteenable(true, true, true, true);

Thank you very much!
Your answer helped me solve my problem. I would just like to correct you on one point: the function to use is gpu_set_colourwriteenable and not gpu_colourwriteenable!
Even if I'm not sure I understood exactly this solution, I'm very happy with the result. I'll look into why it works.