Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-23-2010, 03:19 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
Preview: Text Animations

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 onCreated(){
  
this.join("personal_adam_anitext");
  
this.msg2 newText(this300screenwidth/3screenheight+10"This is some great Testing text."1nulltrue);
  
this.msg2.addActions( { {"doMove"2screenwidth/3,screenheight/3},{"doFade",2,1},{"doZoom"2,5}});
  
this.msg2.addActions( { {"doZoom"21} });
  
this.msg2.addActions( { {"doDelay"1}});
  
this.msg2.addActions( { {"NewText""I'm off now, cya."},{"doDelay"2} });
  
this.msg2.addActions( { {"doMove"1screenwidthscreenheight/3},{"doFade",2,0},{"doZoom"2,.1}});
  
this.msg2.addActions( {{ "doFade"11} ,{"doZoom"1.1}} );
  
this.msg2.addActions( {{"doMove"1screenwidth/3,screenheight/3}});
  
this.msg2.addActions( {{"doFade"50} ,  {"doZoom"51.5}, {"doDelay"10}});
  for (
temp.0temp.10temp.++ ){
    
this.msg2.addActions ( { {"doMove"2random(0,screenwidth-10),random(0,screenheight-10) },{"doFade"2random(.2,1)},{"doZoom"2random(.1,4)} } );
    
this.msg2.addActions ( {{"doFade".50}});this.msg2.addActions({{"NewText""Action: " temp.i+@" of 10"},{"doFade",.5,1}});
  }
  
this.msg2.start();

And the class.
PHP Code:
//#CLIENTSIDE

function newText(temp.scopetemp.start_itemp.xtemp.ytemp.texttemp.zoomFactortemp.textColortemp.useBackgroundtemp.bgColortemp.bgPaddingtemp.borderColortemp.borderThickness){
  
// Various Declarations to start with.
  
temp.= 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.temp.xtemp.t.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.zoomtemp.t.font""temp.t.text); // initial width/height,   recalculated on zoom always
  
temp.t.height gettextheight(temp.t.zoomtemp.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.addActions = function ( temp.actions ) {
    
this.queue.addtemp.actions );
    
this.count++;
  };

  
temp.t.onUpdate = function () {
    if (!
this.started)return;
      for (
temp.actionthis.queue[0]){
        if (
temp.action[0in {"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.gthis.garbage){
      for (
temp.0temp.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() == && 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);
  };

  
temp.t.doFade = function (action) {
    
temp.time temp.action[1];
    
temp.newAlpha temp.action[2];
    if (
this.fadeDist == null) {
      
this.fadeDist temp.newAlpha this.alpha;
      
this.fadeStep this.fadeDist/(temp.time*20);
    }
    if (
abs(temp.newAlpha this.alpha) <= this.fadeStep){
      
this.alpha temp.newAlpha;
    }else 
this.alpha += this.fadeStep;

    if (
this.alpha == temp.newAlpha){
      
this.fadeDist null;
      
this.fadeStep null;
      return 
true;
    }else return 
false;
  };

  
temp.t.doDelay = function (action) {
    
temp.time int(temp.action[1]*100)/100;
    if (
this.delayTime == null){
      
this.delayTime temp.time;
    }
    
this.delayTime -= .05;
    if (
this.delayTime <= 0){
      
this.delayTime null;
      return 
true;
    }else return 
false;
  };
  
  
temp.t.doZoom = function (action) {
    
temp.time int(temp.action[1]*100)/100;
    
temp.newZoom int(temp.action[2]*100)/100;
    if (
this.zoomDist == null) {
      
this.zoomDist temp.newZoom this.zoom;
      
this.zoomStep = (this.zoomDist*.05)/(temp.time);
    }
    if (
abs(temp.newZoom this.zoom) <= this.zoomStep){
      
this.zoom temp.newZoom;
    }else 
this.zoom += this.zoomStep;
    
    
this.NewText(this.text);
    if (
this.zoom == temp.newZoom){
      
this.zoomDist null;
      
this.zoomStep null;
      return 
true;
    }else return 
false;
  }; 
  
  
temp.t.doMove = function (action) {
    
temp.time int(temp.action[1]*100)/100;
    
temp.newx int(temp.action[2]);
    
temp.newy int(temp.action[3]);
    if (
this.moveStep == null){
      
temp.dx temp.newx this.x;
      
temp.dy temp.newy this.y;
      
temp.dist = (temp.dx^temp.dy ^2)^.5;
      
temp.addx = (temp.dx/temp.dist)*(temp.dist*.05/temp.time);
      
temp.addy = (temp.dy/temp.dist)*(temp.dist*.05/temp.time);
      
this.moveStep = {temp.addxtemp.addy};
    }

    if (
abs(temp.newx this.x) <= this.moveStep[0]){
      
this.temp.newx;
    }else 
this.+= this.moveStep[0];
    
    if (
abs(temp.newy this.y) <= this.moveStep[1]){
      
this.temp.newy;
    }else 
this.+= this.moveStep[1];
    
    if (
this.== temp.newx && this.== temp.newy){
      
this.moveStep null;
      return 
true;
    }else return 
false;
  };

  
temp.t.NewText = function (newText) {
    
this.text temp.newText;
    
this.width gettextwidth(this.zoomthis.font""this.text); 
    
this.height gettextheight(this.zoomthis.font"");
  };

  
temp.t.draw = function (){
    
temp.this.start_i;
    
with (this.global.findimg(temp.i)){
      
thiso.x;  thiso.y;
      
text thiso.text;
      
red thiso.textColor[0];  green thiso.textColor[1];  blue thiso.textColor[2];
      
zoom thiso.zoom;
      
font thiso.fontstyle thiso.style;
      
layer thiso.layer;
      
alpha thiso.alpha;
      
mode 1;
    }
    
temp.i++;
    if (!
this.background) return temp.i;
    
with (this.global.findimg(temp.i)){
      
temp.xx=thiso.x;temp.yy=thiso.y;temp.w=thiso.width;temp.h=thiso.height;temp.p=thiso.bgPadding;
      
polygon = {xx-p,yy-p,
                 
xx+w+p,yy-p,
                 
xx+w+p,yy+h+p,
                 
xx-p,yy+h+p};
      
temp.p2 temp.p+thiso.borderThickness;
      
temp.poly2 = {xx-p2,yy-p2,
                 
xx+w+p2,yy-p2,
                 
xx+w+p2,yy+h+p2,
                 
xx-p2,yy+h+p2};

                 
      
layer thiso.layer 1;
      
red thiso.bgColor[0]; green thiso.bgColor[1]; blue thiso.bgColor[2];
      
alpha thiso.alphamode 1;
    }
    
temp.i++;
    
with (this.global.findimg(temp.i)){
      
polygon temp.poly2;
      
layer thiso.layer -2;
      
red thiso.borderColor[0]; green thiso.borderColor[1]; blue thiso.borderColor[2];
      
alpha thiso.alphamode 1;
    }
    
temp.i++;
    
this.lasti temp.i;
    return 
temp.i;
  };
 
  return 
temp.t;

__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.