Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, I realize that you're not looking for the following 'solution', which won't work, as all frames will still be played:</p> <pre><code>stage.frameRate = new_frame_rate; </code></pre> <p>The only solution is to just skip frames in your enterFrame callback:</p> <pre><code>// Defined elsewhere. var current_frame:Number = 0; var frame_skip_factor:uint; // Skip one frame every 'x' frames. var is_frame_skip_active:Boolean; function on_enter_frame(event:Event):void { if ( is_frame_skip_active &amp;&amp; current_frame++ % frame_skip_factor == 0) { return; } // Game logic/rendering code... } </code></pre> <p>(assuming, per best practices, you've centralized game logic/animation in a single callback), but that may present race conditions/complications when any asynchronous callbacks are run.</p> <p>There is no way to actually skip frames at the runtime level; this is part of the contract of the AVM - no frames are skipped, all code is ran, no matter what. If performance is an issue, you might try asynchronous code execution. There are a couple of ways to do it:</p> <p>1) Offload some computing to Pixel Bender, so that it can be processed asynchronously and/or in parallel (http://www.adobe.com/devnet/flex/articles/flashbuilder4_pixelbender.html)</p> <p>2) Spread out the execution of lengthy operations over multiple frames (requires a state save and state restore, a la memento pattern). Details (and a great read) here: <a href="http://www.senocular.com/flash/tutorials/asyncoperations/" rel="nofollow">http://www.senocular.com/flash/tutorials/asyncoperations/</a></p> <p>In any case, I'd (first and foremost) recommend definitively identifying the performance bottleneck with a tool like the Flash Builder Profiler or the Stats class (Mr. Doob). </p> <p>Blitting might be the solution (create a spritesheet with a tile for each frame of the animation) as well. But in any case, I think what you'll need to do is subclass MovieClip and override the play(), stop(), and gotoAndPlay() methods. Your class should look something like this:</p> <pre><code>public class MyMovieClip extends MovieClip { override public function play():void { addFrameSkipListener(); super.play(); } override public function gotoAndPlay(frame:Object, scene:String = null):void { addFrameSkipListener(); super.gotoAndPlay(frame, scene); } // .... } </code></pre> <p>Where the frame skip listener will skip frames according to the current frame rate or frame time, if necessary. Naturally, you'll also need to remove the frameSkipListener when the animation has reached an end.</p> <p>While the MovieClip override solution might do what you want on paper, if you have a lot of objects, this might actually degrade performance as the additional ENTER_FRAME listeners will add some overhead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload