Energy Engine
Member
Hello,
First of all, its great to see the GMC back up and running again! Well done to all those involved.
Now the issue. I'm trying to achieve a simple alpha circle effect in GMS. The effect in question is one where a black and white circle sprite (with the whitest part in the center gradually becoming darker moving outward) is applied to a sprite and the whitest parts represent an alpha of close to 1 while the blackest parts represent an alpha close to 0 when applied to a particular sprite. In GM8, this was done easily with the sprite_set_from_alpha function but in GMS, we are required to use surfaces.
I know how surfaces work in theory, but getting them to work, particularly with respect to the above effect, is proving to be difficult. I used the manual's example as close to possible but couldn't get it to work after several attempts and looking for examples/tutorials.
Here's what I have (note that the resource names have been copied from the manual's example):
Create event:
spr_create = true;
Draw Event:
if spr_create
{
spr_create = false;
var surf, spr;
surf = surface_create(sprite_get_width(spr_Explosion_Alpha), sprite_get_height(spr_Explosion_Alpha));
surface_set_target(surf);
draw_clear_alpha(c_black, 0);
draw_sprite(spr_Gradient, 0, 0, 0);
sprite_index = sprite_create_from_surface(surf, 0, 0, sprite_width, sprite_height, false, false, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
draw_clear_alpha(c_black, 0);
draw_sprite(spr_Explosion_Alpha, 0, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
spr = sprite_create_from_surface(surf, 0, 0, sprite_width, sprite_height, false, false, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
surface_reset_target();
surface_free(surf);
sprite_set_alpha_from_sprite(sprite_index, spr);
sprite_delete(spr);
}
draw_sprite(sprite_index, 0, 0, 0);
Room End:
sprite_delete(sprite_index);
NOTE: spr_Explosion_Alpha is intended to be the sprite to which the alpha circle applies and spr_Gradient is the alpha sprite itself.
Despite all this, all I get is a blank background. I'm not quite sure what the problem is. I've changed the clear alpha values, x and y values, sprite names etc. but I keep getting a blank screen. Any help to get the desired effect to work would be appreciated.
Thanks!
First of all, its great to see the GMC back up and running again! Well done to all those involved.
Now the issue. I'm trying to achieve a simple alpha circle effect in GMS. The effect in question is one where a black and white circle sprite (with the whitest part in the center gradually becoming darker moving outward) is applied to a sprite and the whitest parts represent an alpha of close to 1 while the blackest parts represent an alpha close to 0 when applied to a particular sprite. In GM8, this was done easily with the sprite_set_from_alpha function but in GMS, we are required to use surfaces.
I know how surfaces work in theory, but getting them to work, particularly with respect to the above effect, is proving to be difficult. I used the manual's example as close to possible but couldn't get it to work after several attempts and looking for examples/tutorials.
Here's what I have (note that the resource names have been copied from the manual's example):
Create event:
spr_create = true;
Draw Event:
if spr_create
{
spr_create = false;
var surf, spr;
surf = surface_create(sprite_get_width(spr_Explosion_Alpha), sprite_get_height(spr_Explosion_Alpha));
surface_set_target(surf);
draw_clear_alpha(c_black, 0);
draw_sprite(spr_Gradient, 0, 0, 0);
sprite_index = sprite_create_from_surface(surf, 0, 0, sprite_width, sprite_height, false, false, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
draw_clear_alpha(c_black, 0);
draw_sprite(spr_Explosion_Alpha, 0, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
spr = sprite_create_from_surface(surf, 0, 0, sprite_width, sprite_height, false, false, 0,0) //sprite_get_xoffset(spr_Gradient), sprite_get_xoffset(spr_Gradient));
surface_reset_target();
surface_free(surf);
sprite_set_alpha_from_sprite(sprite_index, spr);
sprite_delete(spr);
}
draw_sprite(sprite_index, 0, 0, 0);
Room End:
sprite_delete(sprite_index);
NOTE: spr_Explosion_Alpha is intended to be the sprite to which the alpha circle applies and spr_Gradient is the alpha sprite itself.
Despite all this, all I get is a blank background. I'm not quite sure what the problem is. I've changed the clear alpha values, x and y values, sprite names etc. but I keep getting a blank screen. Any help to get the desired effect to work would be appreciated.
Thanks!