actionscript 3 - Stop function creating bitmaps/reduce cpu overload/reduce lag -


hi i'm noticing following code producing noticeable chunk of lag when incorporated.

    public function impassable_collisions():void { //prevent player moving through impassable mcs          each(var mc:movieclip in impassable) {          var bitmap = createbitmapclone(mc); //return clone of bitmap of mc, accounting transformations          var bounds:rectangle = player.getrect(bitmap);         var playercenterx:number = bounds.left + bounds.width * .5;         var playercentery:number = bounds.top + bounds.height * .5;          //test pixel perfect collision against shape based on point , radius,          //returns angle of hit or nan if no hit.         var hitangle:number = hittestpointangle(bitmap, playercenterx, playercentery, player.height/2);          if(!isnan(hitangle)){             // move player away object             player.x -= int(math.cos(hitangle) * player.speed*timediff);             player.y -= int(math.sin(hitangle) * player.speed*timediff);         }     } } 

so function called function called enterframe listener. i'm looping through array containing perhaps between 5-30 movieclips @ given time, given mc cloned bitmap , bitmap used test collisions between , bitmap (the "player"). i'm assuming rather inefficient taking place , producing lag - more choppy-like movements when "player" moved. have idea problem is/solutions it?

sorry rather vague question title

thanks

pixel perfect collision detection expensive. can't problem, can tell it's expensive in terms of processing.

creating new bitmap each iteration in loop expensive.

one thing can try eliminate objects before doing more intensive checking. example quick distance check can eliminate need test object if aren't within distance.

if (distance <= threshold) {     // create bitmap check     // expensive pixel perfect collision check } 

your goal eliminate objects not close enough collide.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -