开发者

Stop rendering in Flash w/ ActionScript 3

开发者 https://www.devze.com 2023-02-24 23:02 出处:网络
Here\'s my problem: I have a few display objects that are modified by a loop, and I would like flash to render exactly one frame at the end of each loop. Duration of a loop may vary unpredictably, thu

Here's my problem: I have a few display objects that are modified by a loop, and I would like flash to render exactly one frame at the end of each loop. Duration of a loop may vary unpredictably, thus a constant frame-rate won't do it.

I found a hack-ish way to render one frame at the end of each loop, using updateAfterEvent with a 0ms timer. Now I want to prevent Flash from rendering frames in the middle of the loop: this is a waste of time and ressources, and produces strange blinking effects. Setting the frame rate to 0 would be an easy solution, but stage.frameRate has a minimum value of 0.01.

Question 1: Is there a way to properly stop the standard rendering loop? A workaround will not be regarded as a valid answer, because what I'm currently doing is a pretty good workaround (1 frame every 100 seconds is bearable).

Question 2: Is there a better way than updateAfterEvent to force rendering?

Oops, I forgot civilities开发者_JAVA百科. Good morning/afternoon, please, thanks in advance.


There's nothing wrong with using updateAfterEvent to force rendering ahead of the next scheduled render update, but your wasteful timer is undesirable (too many function calls). Instead, dispatch your own render event at the end of the loop, listen for it, and updateAfterEvent() then.

That said, you should not see things rendering in the middle of a loop, if what we're talking about is a for, while, etc.. loop. Flash doesn't render during synchronous code execution. That part has me wondering what's really going on in your code.


There are different ways to go about this, though this seems like a problem with your design overall rather than limitations within Flash. I think a long while loop tends to be a bad idea .... If you need full control I would offscreen render everything rather than attach your current objects to the DisplayList. This requires addChild'ing everything to a non-attached sprite, then drawing it when you want. The drawback here is that you won't get any mouseevent/keyboardevent.

Looks like:

var bmp:BitmapData = new BitmapData(800,600,true);
var container:Sprite = new Sprite();

// add all your display objects to the container

stage.addChild(new Bitmap(bmp))

// render loop
for each (var dsp:DisplayObject in objects) {
    // stuff
}

// clear our bitmap
bmp.fillRect(bmp.rect, 0);
bmp.draw(someContainer);
0

精彩评论

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