How to go about optimising this class?


i'm rather new actionscript, i'm figuring out go.

 

i making game. 1 of primary features of game darkness. chose use tiles represent areas outside players sight range, works great on small scale. problem once there's lots of darkness tiles gets bit laggy.

 

this class light sources, proof of concept.. plan on having in betweens later not true or false.

package {     import flash.display.movieclip;     import flash.events.event;         public class lightemitter extends movieclip     {         private var i:int = 0;         private var closesth = 0;         private var lightresistance = 0;         private var brightness = 1;         private var targettile;         private var basesightlevel = 400;           public function lightemitter()          {             this.parent.setchildindex(this, 0)             stage.addeventlistener(event.enter_frame, onjoinframe);         }         public function onjoinframe(e:event)          {                 //hide darkness             (i = 0; < maindocument.darktiles.length; ++)               {                 targettile = maindocument.darktiles[i][0]                 lightresistance = maindocument.darktiles[i][1];                    if (math.sqrt(math.pow(targettile.x-this.x, 2) + math.pow(targettile.y-this.y, 2)) < (basesightlevel*brightness)/lightresistance)                 {                     targettile.alpha = 0;                 }                 else                 {                     targettile.alpha = 0.6;                 }              }             this.x = parent.getchildbyname("player").x             this.y = parent.getchildbyname("player").y         }     } } 

 

 

 

this class tile of darkness.

package {     import flash.display.movieclip;      public class fog extends movieclip     {         var adarktile: array = new array();          public function fog()          {             adarktile[0] = this;             adarktile[1] = 1;             maindocument.darktiles[maindocument.darktiles.length] = adarktile;         }      }  } 

 

 

i need load lots of tiles @ time in addition other elements of game. (but can unload, or @ least hide, tiles off screen)

any suggestions/tips/alternatives appreciated.

enable cacheasbitmap property of tiles , remove tiles no longer on stage.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account