简体   繁体   中英

AS3 framerate change issue

I have a KeyboardEvent that switches Boolean, if true an FR var drops -2/frame to a bottom of 10, if false it rises +2/frame to a top of 60. It works fine going up and down but whenever I add "stage.frameRate = FR;" to an ENTER_FRAME function and play it, it freezes the control over the window. Animation still plays but I can't turn it off unless via Ctrl-Alt-Del.

1.Why is this happening?

2.Is it possible to change frameRate every frame?

3.If yes, how?

Um, I am not sure playing with the frame rate on the fly is a good thing to be doing. What are you trying to do? Perhaps there is a better way...

This is a total guess, but perhaps when you set the frame rate to the stage it initialises 'something' in the background. Then since you have it happening every frame, it'll try to initialises on every frame, causing it to be locked up.


Updating answer to include an example of using a Timer object:

import flash.utils.Timer;
import flash.events.TimerEvent;

// the timer takes in milliseconds, so for 30 frames/second, you would have a frame tick at every 1000 / 30, or 33.333ms
var tickSpeed:int = 1000 / 30;
var frameTick:Timer = new Timer(tickSpeed, 0);


function enterFrameListener(inputEvent:Timer):void {
    // this method will run on every timer tick
}
frameTick.addEventListener(TimerEvent.TIMER, enterFrameListener);

// can change the tick speed of the timer like so (setting it to 1000 means 1 frame tick every second)
frameTick.delay = 1000;

// according to the api doc however, a tickspeed of less then 20ms is not recommended
// 20ms would be equal to 60 fps

By offloading it to a timer, you shouldn't need to mess around with the overall framerate with another advantage of other objects can be affected by different timers at the same time. Timer class also has a few helpful methods in itself as well: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html

I think your app is freezing because you are trying to set the frame rate on every frame, i would suggest you should check your frame rate in your ENTER_FRAME section. if your frame rate goes up/down from you desired frame rate, then you should set your frame rate to FR.

Try this can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM