This is the script I use for fading on Val Dev, it is to be joined to a Gui Control object.
PHP Code:
//#CLIENTSIDE
enum {
M_NONE,
M_FADEIN,
M_FADEOUT
}
public function fadeIn(time, toalpha) {
if (this.fademode != M_NONE)
return;
this.fademode = M_FADEIN;
this.fadeint = 0.05 / time;
this.fadeto = toalpha;
this.visible = true;
this.fading = true;
setTimer(0.05);
}
public function fadeOut(time, toalpha) {
if (this.fademode != M_NONE)
return;
this.fademode = M_FADEOUT;
this.fadeint = 0.05 / time;
this.fadeto = toalpha;
this.visible = true;
this.fading = true;
setTimer(0.05);
}
function onTimeout() {
switch (this.fademode) {
case M_FADEIN:
this.alpha += this.fadeint;
if (this.alpha >= this.fadeto) {
this.fademode = M_NONE;
this.fading = false;
setTimer(0);
}
else {
setTimer(0.05);
}
break;
case M_FADEOUT:
this.alpha -= this.fadeint;
if (this.alpha <= this.fadeto) {
this.fademode = M_NONE;
if (this.fadeto == 0) {
this.visible = false;
}
this.fading = false;
setTimer(0);
}
else {
setTimer(0.05);
}
break;
}
}