brice_platinum
Member
Hello everybody, I'm trying to make a simple fade effect between two sprites and i got in to a problem.
This is what I am expecting to get
I created 2 sprites with the pictures and a simple background with a blue dot in the middle.
Now what I want is the first image starts to fade away at the same time the second image starts appearing, to achieve this i just created 2 variables "fade_in" and "fade_out" that varies its values from 1 to 0 according to the situation, now in the draw event i put this:
But the actual result is this:
The pixels of the intersection gets alpha values diferent from 1 and the background gets visible. I know this is working as intended but how can I get the transition without the transparency problem?
The only solution that comes in to my mind is to draw the first image, then in a second surface draw the background and the second picture, and finally draw the surface with the "fade_in" variable wich is what I used to achieve the first pic:
To get things worse, I actually need to draw all this using surfaces, wich its a mess when trying to use alpha values so this is what I learned:
The solution that comes in to my mind is to somehow set the alpha value of the pixels en the intersections to 1 in the surface, but how can I do this??
Hope you guys can help me. I'm providing the .yyz I used to show this in case someone is interested.
This is what I am expecting to get
I created 2 sprites with the pictures and a simple background with a blue dot in the middle.
Now what I want is the first image starts to fade away at the same time the second image starts appearing, to achieve this i just created 2 variables "fade_in" and "fade_out" that varies its values from 1 to 0 according to the situation, now in the draw event i put this:
GML:
draw_sprite_ext(sImage1,0,0,0,1,1,0,c_white,fade_out);
draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,fade_in);
The pixels of the intersection gets alpha values diferent from 1 and the background gets visible. I know this is working as intended but how can I get the transition without the transparency problem?
The only solution that comes in to my mind is to draw the first image, then in a second surface draw the background and the second picture, and finally draw the surface with the "fade_in" variable wich is what I used to achieve the first pic:
GML:
draw_sprite_ext(sImage1,0,300,0,1,1,0,c_white,1); //Draw the first pic in the application surface
surface_set_target(surf1);
draw_sprite_ext(sBackground,0,0,0,1,1,0,c_white,1); //Draw the background in the surface
draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,1); //Draw the second pic in the surface
surface_reset_target();
draw_surface_ext(surf1,300,0,1,1,0,c_white,fade_in);//Draw the surface with the alpha value
GML:
gpu_set_blendmode_ext(bm_one, bm_inv_src_alpha); //Setting the blendmode
surface_set_target(surf3);
draw_clear_alpha(c_black,0);
shader_set(sh_premultiply_alpha); //Using a provided shader to premultiply the alpha
draw_sprite_ext(sImage1,0,0,0,1,1,0,c_white,fade_out);
draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,fade_in);
shader_reset();
surface_reset_target();
draw_surface_ext(surf3,600,0,1,1,0,c_white,1);
gpu_set_blendmode(bm_normal);
Hope you guys can help me. I'm providing the .yyz I used to show this in case someone is interested.