Gradual Image Fadeout To Object Destroy

In this novice tutorial, we will teach you how to make an object gradually fade away, and be destroyed when it's completely faded.

Fading object: Create event

fading=0;
image_alpha=1;

fading is a variable we will use to determine when we want the object to fade out. image_alpha is to make sure that the object starts completely opaque (usually this is not needed, as all objects start with image_alpha of 1 anyway).

Fading object: Event which triggers fading

fading=1;

This sets fading to 1, which we will program the object's Step event to recognise.

Fading object: Step event

if fading=1
{
image_alpha-=0.05;
}

if image_alpha<=0
{
instance_destroy();
}

The first half of this code will make the object fade out when variable fading is equal to 1 (which is set when the fading trigger happens). The -=0.05 is a relative indicator. This means that, every step, the image's alpha value will decrease by 0.05.

The second half looks at when the image's alpha value is less than or equal to zero. When this happens, the object is destroyed. If this did not occur, the object would still exist, but be invisible.

Written by NAL

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License