Some code to animate text on the screen prettily, This is just a prototype version though. It's not fully done yet.
PHP Code:
//NPC Created by Rogue Shadow (TCN)
//AIM: RogueTCN
//FORUM PM: adam
// Special messaging prototype 2
//#CLIENTSIDE
// Actions
// { "doFade" , time , value 0-1 }
// { "doMove" , time , new x , new y }
// { "doZoom" , time , value } - 0 doesn't seem to be a good value for zoom on the text, didn't test in opengl mode yet.
// { "doDelay", time , value } delays by the specified amount of time.
// { "NewText" , time , value } instantly changes text, the border sizes follow
// Planned Actions
// { "doTextColor" , time , {red, green, blue} } - transition from current color to new one smoothly over time.
// { "doBgColor" , time , {red, green, blue} } - transition from current color to new one smoothly over time.
// { "doOutlineColor" , time , {red, green, blue} } - transition from current color to new one smoothly over time.
// { "doDestruct" } - yeah... almost forgot this feature. The text will go away soon (but not right away) after you delete it's variable
// But this will do it right, when added.
// While I'd love to add rotation, it is beyond difficult o.O and insanely complex,
// unless the methods i've thought of are wrong.
function newText(temp.scope, temp.start_i, temp.x, temp.y, temp.text, temp.zoomFactor, temp.textColor, temp.useBackground, temp.bgColor, temp.bgPadding, temp.borderColor, temp.borderThickness){
// Various Declarations to start with.
temp.t = new TStaticVar(); // All contained in a single TStaticVar (which is basically a whole script within a script, there are other ways, but this one is fun too.)
temp.t.global = temp.scope; // Saving the scope seems to make it easier to do things like, draw images, and access other things from within the script here.
temp.t.start_i = temp.start_i; // The index we start drawing from, incrementing until we're done drawing things.
temp.t.x = temp.x; temp.t.y = temp.y; // x,y position of the top-left corner of the text. The actual image drawn will extend beyond this by the amount of temp.bgPadding and the borderThickness
temp.t.textColor = (temp.textColor != null) ? temp.textColor:{1,1,1}; temp.t.alpha = 0; // Default color white, alpha starts at 0 (suggesting Fading in whenever possible)
temp.t.layer = 10*temp.start_i; // layer 10 times the drawing index, to allow overlapping text rather than smooshing together text.
temp.t.font = "Comic Sans MS"; temp.t.style = ""; // Default font and style here.
temp.t.zoom = (temp.zoomFactor != null) ? temp.zoomFactor:1; // default zoom of 1, or what you select.
temp.t.text = temp.text; // save that text
temp.t.width = gettextwidth(temp.t.zoom, temp.t.font, "", temp.t.text); // initial width/height, recalculated on zoom always
temp.t.height = gettextheight(temp.t.zoom, temp.t.font, "");
temp.t.queue = {};
if (temp.useBackground != null){
temp.t.background = useBackground; // if were using the background
temp.t.bgPadding = (temp.bgPadding != null) ? temp.bgPadding:2; // how far the background extends beyond the text itself
temp.t.borderThickness = (temp.borderThickness != null) ? temp.borderThickness:2; // the thickness of the backgrounds outline
temp.t.bgColor = (temp.bgColor != null) ? temp.bgColor:{0,0,0}; // it's color, default black
temp.t.borderColor = (temp.borderColor != null) ? temp.borderColor:{1,1,1};
}
temp.t.start = function () {
this.started = true;
this.onUpdate();
};
temp.t.stop = function () {
this.started = false;
};
temp.t.onUpdate = function () {
if (!this.started)return;
for (temp.action: this.queue[0]){
if (temp.action[0] in {"doZoom", "doMove", "doFade", "doDelay"}){
if (this.(@temp.action[0])(temp.action))this.garbage.add(temp.action);
}elseif(temp.action[0] == "NewText"){
this.NewText(temp.action[1]); this.garbage.add(temp.action);
}else this.garbage.add(temp.action);
}
for (temp.g: this.garbage){
for (temp.i = 0; temp.i < this.queue[0].size(); temp.i++){
if (temp.g[0] == this.queue[0][temp.i][0]){
this.queue[0].delete(temp.i);
break;
}
}
}
this.garbage = "";
if (this.queue[0].size() == 0 && this.queue.size() > 0){
this.queue.delete(0);
//echo("Completed actions, moving to next set.");
}
this.draw();
//this.cancelevents("Update");
this.scheduleevent(0.05, "Update", null);
};