1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/**
Fade.c
Function to fade in and out objects.
@author
*/
global func FadeOut(int time, bool del)
{
// If there is an existing effect, remove it.
if (GetEffect("ObjFade", this))
RemoveEffect("ObjFade", this);
// Add the effect itself.
var effect = AddEffect("ObjFade", this, 1, 1);
effect.fade_time = time;
effect.fade_out = true;
// Delete the object when fade-out is done.
effect.delete = del;
return effect;
}
global func FadeIn(int time)
{
// If there is an existing effect, remove it.
if (GetEffect("ObjFade", this))
RemoveEffect("ObjFade", this);
// Add the effect itself.
var effect = AddEffect("ObjFade", this, 1, 1);
effect.fade_time = time;
return effect;
}
global func FxObjFadeTimer(object target, proplist effect, int timer)
{
// Is the fade timer up?
if (timer >= effect.fade_time)
{
// Delete object at end if specified.
if (effect.delete)
target->RemoveObject();
else
{
if (effect.fade_out)
{
// Callback to object when alpha is completely transparent.
target->~OnFadeDisappear();
target->SetObjAlpha(0);
}
else
{
// Callback to object when alpha is fully opaque.
target->~OnFadeAppear();
target->SetObjAlpha(255);
}
}
return FX_Execute_Kill;
}
// Find out what the alpha should be.
var alpha = (timer * 1000 / effect.fade_time) * 255 / 1000;
// Does the object fade out or in?
if (effect.fade_out)
alpha = 255 - alpha;
// Shade object's alpha to match time.
target->SetObjAlpha(alpha);
return FX_OK;
}
|