• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code draw_set_alpha does nothing?

rIKmAN

Member
I know this sounds completely stupid, but could somebody please test draw_set_alpha()?

I was having issues with layer_sprite_alpha() seemingly doing nothing, and ended up working backwards only to find out that draw_set_alpha doesn't seem to work either.

I've just made a test project with 2 rectangles, one set to have an alpha value of 0.2, and another which follows the mouse x/y and goes behind it at 1.0 and should show through, but both stay completely opaque.

Link here to .yyz

It's such a simple thing that I'm thinking it can't be a bug, but then it's only 3 lines of code and it's such an obvious thing that surely it would have been found by now?
Code:
// Draw Event
draw_set_alpha(0.2);
draw_self();
draw_set_alpha(1.0);
I'm wondering whether I'm just being an idiot or whether if there's something wrong with my system, drivers or something - but all other software / games work fine, I have no issues with anything else and would appreciate it anyone could test the .yyz I linked or test the commands themselves and let me know if it works for them so I can track down my issue.

Thanks!
 
Last edited:

Geoff Jones

Member
Its working as intended on my project.

Code:
draw_set_alpha(textalpha)
draw_set_font(global.smallfont)
draw_set_color(c_red)
draw_text(x, y, o_player.damage)
draw_set_alpha(1)
draw_set_color(c_white)
textalpha is a varible that goes from 1-0 fading after every 0.2 seconds.
 

rIKmAN

Member
Its working as intended on my project.

Code:
draw_set_alpha(textalpha)
draw_set_font(global.smallfont)
draw_set_color(c_red)
draw_text(x, y, o_player.damage)
draw_set_alpha(1)
draw_set_color(c_white)
textalpha is a varible that goes from 1-0 fading after every 0.2 seconds.
I know this is cheeky, but could you quickly try my attached .yyz - it's 20kb in size.

I doubt it's a bug as I said as it's so stupidly obvious, but it isn't working here.
 

Geoff Jones

Member
That function doesn't effect sprites. Only built-in draw functions like draw_rectangle, I think primitives and draw_text. (Same thing with gms1.4)
You need to change image_alpha.
The manual says it works on sprites. "draw_set_alpha ---- .........and will affect all further drawing, including backgrounds, sprites, fonts, primitives and 3D."
 

rIKmAN

Member
That function doesn't effect sprites. Only built-in draw functions like draw_rectangle and draw_text.

You need to change image_alpha.
Ah dammit, yeah it works if I use image_alpha - thanks Bingdom!

It should mention this in the docs, the first line of the manual entry for draw_set_alpha() says:
With this function you can set the base draw alpha for the game.
which implies it affects everything in the "game".

Spent time fudging around wondering why it wasn't working last night and then the servers went down and I couldn't login - what a productive weekend!
 

Bingdom

Googledom
The manual says it works on sprites. "draw_set_alpha ---- .........and will affect all further drawing, including backgrounds, sprites, fonts, primitives and 3D."
I wouldn't fully depend on the manual, it has proven to be unreliable at times.
Check out this reddit post.
Someone mentions that the problem also occurs in gm8
 

rIKmAN

Member
I wouldn't fully depend on the manual, it has proven to be unreliable at times.
Check out this reddit post.
Someone mentions that the problem also occurs in gm8
I know what you're saying, but the manual is the first port of call for any software - especially programming / APIs etc.
How is anyone meant to know draw_set_alpha only works for draw_rectangle etc unless it says so in the manual?

@Nocturne - Maybe add a little line to the draw_set_alpha docs to make it a little clearer?
 

Geoff Jones

Member
Seems so, although as I mentioned in my OP I didn't get any results from layer_sprite_alpha() either which is how I worked backwards to find out about draw_set_alpha, so if you wanted to give that a quick test I'd really appreciate it?
No worries. layer_sprite_alpha() worked fine for me

Code:
//draw event
layer_sprite_alpha("Instances", 0.2)
draw_self()
 
E

Ephemeral

Guest
My first guess is that draw_self() simply ignores the global alpha value the same way it ignores the global color value.

Did you try this?
Code:
draw_set_alpha(0.2);
draw_sprite(sprite_index, image_index, x, y);
draw_set_alpha(1);
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, so draw_set_alpha DOES affect everything, except where you override it. So, if you have an instance with a sprite and NO draw event, and then call draw_set_alpha(0.5), the instance will be rendered at 0.5 alpha. The same if you draw the sprite using draw_sprite(). HOWEVER, draw_sprite_ext has an alpha argument, and so you are overriding the game alpha for a custom value (and draw_self() too, as it is essentially draw_sprite_ext() with the built in variables added for you, so unless you set the image_alpha variable to the same as the draw alpha, it will look different as well). I'll add a note to the draw_set_alpha page mentioning this.
 

rIKmAN

Member
Okay, so draw_set_alpha DOES affect everything, except where you override it. So, if you have an instance with a sprite and NO draw event, and then call draw_set_alpha(0.5), the instance will be rendered at 0.5 alpha. The same if you draw the sprite using draw_sprite(). HOWEVER, draw_sprite_ext has an alpha argument, and so you are overriding the game alpha for a custom value (and draw_self() too, as it is essentially draw_sprite_ext() with the built in variables added for you, so unless you set the image_alpha variable to the same as the draw alpha, it will look different as well). I'll add a note to the draw_set_alpha page mentioning this.
Ahhhh that explains it - yeah a note in the docs would save any future confusion, I was head scratching for a while! :)
 

gnysek

Member
Code:
draw_self() == draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha)
Which means you're overriding draw_set_alpha() by image_alpha in this case, as draw_set_alpha() doesn't applies to functions which sets alpha as one of params.
 
Okay, so draw_set_alpha DOES affect everything, except where you override it. So, if you have an instance with a sprite and NO draw event, and then call draw_set_alpha(0.5), the instance will be rendered at 0.5 alpha. The same if you draw the sprite using draw_sprite(). HOWEVER, draw_sprite_ext has an alpha argument, and so you are overriding the game alpha for a custom value (and draw_self() too, as it is essentially draw_sprite_ext() with the built in variables added for you, so unless you set the image_alpha variable to the same as the draw alpha, it will look different as well). I'll add a note to the draw_set_alpha page mentioning this.
I've been using GM for years, and never knew this, haha! As far as I knew, it only effected text and things like that, like Bingdom said. Never ran into any trouble. Weird.
 

Perseus

Not Medusa
Forum Staff
Moderator
@Nocturne: Are you sure about this? Unless you guys have changed something, draw_set_alpha shouldn't affect sprites (drawn manually or not) at all. This question was raised numerous times on the legacy forums and the development team (including Mark Overmars) always said that the function was not meant for sprites. That's why it was put in "Drawing Shapes" section of the manual and its manual entry mentioned its use being limited to primitives.

The Manual said:
draw_set_alpha(alpha) Sets the alpha transparency value to be used from now on for drawing primitives. Should lie in the range 0-1. 0 is fully transparent, 1 is fully opaque.
The examples you mentioned do not work in any GM version I used to test this. Calling draw_set_alpha affects neither automatically drawn instances nor sprites drawn via draw_sprite. The legacy manual seems to be true in this regard. Whatever is handled as primitives internally is affected by the function.
 

rIKmAN

Member
@Nocturne: Are you sure about this? Unless you guys have changed something, draw_set_alpha shouldn't affect sprites (drawn manually or not) at all. This question was raised numerous times on the legacy forums and the development team (including Mark Overmars) always said that the function was not meant for sprites. That's why it was put in "Drawing Shapes" section of the manual and its manual entry mentioned its use being limited to primitives.

The examples you mentioned do not work in any GM version I used to test this. Calling draw_set_alpha affects neither automatically drawn instances nor sprites drawn via draw_sprite. The legacy manual seems to be true in this regard. Whatever is handled as primitives internally is affected by the function.
What manual are you referring to?
It says the same thing in both the 1.4 and 2.0 manual for draw_set_alpha():
With this function you can set the base draw alpha for the game. This value can be set from 0 to 1 with 0 being fully transparent and 1 being fully opaque (the default value), and will affect all further drawing, including backgrounds, sprites, fonts, primitives and 3D.....<snip>
I can't link to the 2.0 manual as the URL doesn't change between pages, but it looks like the text has been copy/pasted from the 1.4 manual.
 

Perseus

Not Medusa
Forum Staff
Moderator
What manual are you referring to?
I'm talking about the manual for legacy versions which was not written and maintained by Nocturne. Check out this page to see what section and description I'm talking about. As I said earlier, draw_set_alpha was never meant for affecting sprites, so I suspect it's most likely an oversight on his end.
 

gnysek

Member
@Nocturne: Are you sure about this?
This was changed in GameMaker Studio. In GMS 5 - 8.1 this was true, that draw_sprite was drawing at alpha = 1.

Same as previously exit in block of code was nearly same as return (it entered another block of code), while at some point (GMS 1.2 or GMS 1.3) all code/DND actions in event were merged into one, so exit was really skipping rest.

Remember that GMS is not old GM by Mark Overmars and lot of things changed, even about basic functions.
 
Top