![]() ![]() I have no idea how efficient or time consuming the above is though. This.removeEventListener(Event.ENTER_FRAME, handleEnterFrame) Īt frame 5 I created a key frame and added the code: this.gotoAndPlay(10) Īt frame 14 I created a key frame and added the code: this.gotoAndPlay(16) Īfter running I got the following trace output: * ENTER_FRAME last frame, stop updating the playhead Trace('before: ' + before + ', current: ' + this.currentFrame) If (this.currentFrame < this.totalFrames) advance to next frame, show playheads position This.addEventListener(Event.ENTER_FRAME, handleEnterFrame) įunction handleEnterFrame(anEvent: Event): void I created a new MovieClip and expanded the timeline to 23 frames.Īt the first frame I added the following code: import ![]() you can perform multiple gotoAndStop calls within a single ENTER_FRAME event (or any other event).Īs test I created a new AS3.0 project within Flash Pro CS5.5.gotoAndStop(frame) will immediately execute the actionscript at frame.I recently ran into something similar maybe the following helps in some way: 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. Naturally, you'll also need to remove the frameSkipListener when the animation has reached an end. Where the frame skip listener will skip frames according to the current frame rate or frame time, if necessary. Override public function gotoAndPlay(frame:Object, scene:String = null):void Your class should look something like this: public class MyMovieClip extends MovieClip But in any case, I think what you'll need to do is subclass MovieClip and override the play(), stop(), and gotoAndPlay() methods. Doob).īlitting might be the solution (create a spritesheet with a tile for each frame of the animation) as well. 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. There are a couple of ways to do it:ġ) Offload some computing to Pixel Bender, so that it can be processed asynchronously and/or in parallel ()Ģ) Spread out the execution of lengthy operations over multiple frames (requires a state save and state restore, a la memento pattern). If performance is an issue, you might try asynchronous code execution. 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. (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. If ( is_frame_skip_active & current_frame++ % frame_skip_factor = 0) Var frame_skip_factor:uint // Skip one frame every 'x' frames.įunction on_enter_frame(event:Event):void The only solution is to just skip frames in your enterFrame callback: // Defined elsewhere. Okay, I realize that you're not looking for the following 'solution', which won't work, as all frames will still be played: ameRate = new_frame_rate The best approach is to adjust your frame rendering technique to accomodate the variable frame rate. This is just the drawing loop, which is inevitably tied to the frame rate.Īnd just so you know, you can't for frame skipping in flash. If you find that low framerates are impacting the accuracy of collision calculations, the run them separately with a timer. RemoveEventListener(Event.ADDED_TO_STAGE, init) Private function init(e:Event = null):void Update your system based on time, not frames.Ĭircle.x += pixelsPerSecond * percentToMove PercentToMove = (thisFrame - lastFrame) / 1000 Get the miliseconds since the last frame Private function onEnterFrame(e:Event):void Private var pixelsPerSecond:Number = 200 Įlse addEventListener(Event.ADDED_TO_STAGE, init) ĪddEventListener(Event.ENTER_FRAME, onEnterFrame) Here is an example of that will move a circle the at the same rate regardless of the frame rate: Use that amount to determine how to move stuff. This will let you know exactly the amount of time that passed since the last frame. And compare that to the value the last time the script was run. In the enterframe, call getTimer() to get the systemtime in miliseconds. Then you can run your main loop on an EnterFrame. ![]() The approach to use, is to think of changes in pixels-per-second, instead of pixels-per-frame. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |