• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Let a Instance fade out

A

Aldran85

Guest
Hello together,
i would like to let a instance fade out before it gets destroyed.
This is my code atm:
sprite_index = spr_enemy_death;
image_alpha = 1;
image_alpha = max(image_alpha - 0.01, 0);
instance_destroy();


But the Instance get destroyed instant like its skipping the alpha part?
 

TailBit

Member
Code:
sprite_index = spr_enemy_death;
image_alpha = max(image_alpha - 0.01, 0);
// If you set it to 1 before inscrementing it, then it will never reach 0, it should have a image_alpha of 1 from default
If(image_alpha == 0) instance_destroy();
it also depends on the event you use, it need to trigger enough times to lower the alpha..

However, instead you could create a object just for the fadeout, and give it the correct sprite before destroying the enemy
Code:
var i = instance_create(x,y,obj_fade)
i.sprite_index = spr_enemy_death;
instance_destroy(); // the enemy is not needed then
obj_fade step event:
Code:
image_alpha -= 0.01;
If(image_alpha <= 0) instance_destroy();
 
A

Aldran85

Guest
Works perfect thank you!
I also added a choose
Code:
var i = instance_create(x,y,obj_fade)
i.sprite_index = choose(spr_1,spr_2,spr_3);
instance_destroy(); // the enemy is not needed then
Thats everything i wanted, thank you again :)
 

kupo15

Member
Hello together,
i would like to let a instance fade out before it gets destroyed.
This is my code atm:
sprite_index = spr_enemy_death;
image_alpha = 1;
image_alpha = max(image_alpha - 0.01, 0);
instance_destroy();


But the Instance get destroyed instant like its skipping the alpha part?
Is this code in the create event? Its getting destroyed because of the last line, instance_destroy. It would still do that in the step event as well

You need to do this instead

Code:
 if image_alpha <= 0
instance_destroy();
 
Top