开发者

Flash(as3) cpu usage steadily climbs to 80+% doing simple fill loop

I've been fiddling with flash lately and I came across this issue. I've noticed that when I do any kind of fill every frame, my cpu usage will slowly and steadily climb until it hits about 85-90%. This happens using the flashPlayerDebugger.exe (from the flex sdk), and also when viewing the swf in a broswer. Memory usage also seems to grow slowly, but never gets out of control.

Here's the simple flash code to reproduce:

   
 import flash.display.Sprite;
 import flash.events.Event;

 public class test extends Sprite 
 {
  public function test():void 
  {
   stage.addEventListener(Event.ENTER_FRAME, everyFrame);
  }

  private function everyFrame(e:E开发者_如何学Pythonvent):void
  {
   this.graphics.beginFill(0x000000);
   this.graphics.drawRect(100, 100, 100, 100);
   this.graphics.endFill();
  }
 }


Seems to work with other fill shapes (i.e. drawRect, drawCircle, etc.), and with beginBitmapFill as well.

I can't seem to find any instance of others having the same issue (having searched the adobe dev forums, actionscript.org, and also this site, among others), so I don't know if it's something on my end, or if it's a flash issue.

I'm running the latest version of flash (currently 10.1.102.64), but I also tried with an older version of flashPlayerDebugger.exe (10.1.53.64) and got the same issue. I'm running windows 7.

Just checking if anyone else has run into this, or if it's something about the way I'm doing my fills/frame loop. Any help would be greatly appreciated.


Note that you are not clearing your graphics every time you draw, but constantly add new filled shapes to the Sprite, which all will be redrawn. Add

this.graphics.clear();

before every draw action, and your performance should be a lot better.

Also: You should always restrain yourself with those ENTER_FRAME loops - in most cases, there will be a less costly solution, like MOUSE_MOVE or Timers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜