Windows Surfaces and opacity trouble (GMS1.4.9999) [Solved]

Brenden

Member
I am using surfaces to draw this ball. I draw the ball and the shadow/highlight at an alpha of 0.3 to the surface at the same time and then draw the surface to the screen. The issue is the shadow/highlight doesn't seem to blend the way it would if I just drew it to the screen.
Here is what it would be if I drew it to the screen:
1597369446493.png
Here is what I am getting after drawing to the surface and then the surface to the screen:
1597369432460.png
The alpha of the shadow/highlight seems to just burn through the ball, showing behind the ball.
I am doing it this way because I need to rotate the ball once, then stretch it, and then rotate it again. Unfortunately you can't do this all at once in the draw_sprite_ext function.

Here is my code:
GML:
///Create
sufBall = surface_create(sprite_width, sprite_height);
surface_set_target(sufBall);
draw_clear_alpha(c_white, 0);
surface_reset_target();

///Draw
if (!surface_exists(sufBall)){
    sufBall = surface_create(sprite_width, sprite_height);
    surface_set_target(sufBall);
    draw_clear_alpha(c_white, 0);
    surface_reset_target();
}

surface_set_target(sufBall);
//The ball
draw_sprite_ext(sHackySack,0,sprite_width/2,sprite_height/2,1,1,image_angle,c_white,1);
//The highlight/Shadow
draw_sprite_ext(sHackySack,1,sprite_width/2,sprite_height/2,1,1,0,c_white,0.3);
surface_reset_target();

//all the vars in here ar arbitrary, if you want them I can get them to you.
draw_surface_ext(sufBall,surfX,surfY,surfW,surfH,surfRot,c_white,1);
 

Cat

Member
I'm not entirely sure what's causing this, but try putting the surface clearing code outside of the if check, e.g.
GML:
///Draw
if (!surface_exists(sufBall)){
    sufBall = surface_create(sprite_width, sprite_height);
}
surface_set_target(sufBall);
draw_clear_alpha(c_white, 0);
surface_reset_target();
 

Brenden

Member
Unfortunately moving the surface clearing code doesn't solve it. Setting it to black with 0 alpha also has no effect. Even if I set the clear to white with full alpha, I get this.
1597376325410.png
 

Brenden

Member
I have found a work around, but still don't know what was causing the issue.
All I did was take the drawing of the shadow out of the surface and drew it after I drew the surface to the screen.
Although I did need to make a new sprite for the shadow and change the origin, since it originated around the center, now it is at the top left corner like the origin is for the surface.


GML:
///Create
sufBall = surface_create(sprite_width, sprite_height);
surface_set_target(sufBall);
draw_clear_alpha(c_white, 0);
surface_reset_target();

///Draw
if (!surface_exists(sufBall)){
    sufBall = surface_create(sprite_width, sprite_height);
    surface_set_target(sufBall);
    draw_clear_alpha(c_white, 0);
    surface_reset_target();
}

surface_set_target(sufBall);
//The ball
draw_sprite_ext(sHackySack,0,sprite_width/2,sprite_height/2,1,1,image_angle,c_white,1);
surface_reset_target();

//all the vars in here ar arbitrary, if you want them I can get them to you.
draw_surface_ext(sufBall,surfX,surfY,surfW,surfH,surfRot,c_white,1);
//The highlight/Shadow
draw_sprite_ext(sHackySackShadow,0,surfX,surfY,surfW,surfH,surfRot,c_white,0.3);
1597377911970.png
My only issue now is why the shadow and ball don't line up like they did in the sprite editor?
 

Brenden

Member
I see, that article helps! Thank you! I'm going to stick with my work around, but that article can defiantly help me out in the future.
 
Top