can I change frame rate while running the swf?I think its useful, but...
Thanks!
Printable View
can I change frame rate while running the swf?I think its useful, but...
Thanks!
Fraid not mate.
There are cheaty kludgy ways of faking it using setInterval, but it's less than ideal.
Squize.
Hi and welcome to FK,
I first suggest you'll go and read the readme sticky on top of the games-page. It'll save you a lot of flaming. When you ask a quesiton, you should be more specific. Those 1-line questions aren't very loved here ;) It tends to look like you're too tired to ask a normal question, and expect us to just answer everything you ask.
Secondly, no it's not possible to change your fps while running the game. (Please forgive me if I'm wrong) But! There is a work-around. You can use the setInterval functions instead of onEnterFrame functions, because these will always stay at the same speed, no matter the fps of the movie. (Although, I've heard they might be a few hundreds of a second faster if you fps is higher)
You should be able to use something like this:
code:
var myInt; // This is where we'll store the interval in (this way we can remove/replace it)
var myFps = 25; // The current fps of your movie
var dir = 1; // Just a variable that we'll use in the 'onEnterFrame'
function myFunc(){ // The function that will be called (and act like the onEnterFrame)
if(dir == 1){
hero._x += 5;
if(hero._x>500){
dir = 0;
myFps = 5;
newInt();
}
} else if(dir == 0){
hero._x -= 5;
if(hero._x<10){
dir = 1;
myFps = 25;
newInt();
}
}
}
function newInt(){ // The function that changes the interval with the new 'fps'
clearInterval(myInt); // First remove the old interval
myInt = setInterval(myFunc, Math.round(1/myFps*1000)); // And build the new one again
}
myInt = setInterval(myFunc, Math.round(1/myFps*1000)); // Calling the interval and setting the 'fps'
Create a hero MC and watch :)
It's quick and rough code and can proberbly be optimized a lot, but it should give you the idea. The fps isn't totaly right, because I had to round down values, so you shouldn't use this to create timers or anything.
SaphuA
Edit: The AS tag is a bit screwed, sorry bout that :p
Thanks for Squize and SaphuA's help,
especially for SaphuA's code :-)
I love here.
According to me, if you put sound on the frames in your movie and use Saphua's code, then the sound might get screwed up...or will it? may be it will.....hmm....
it's not a brilliant way to do things, but you could reload a base level which determines the global fps (attached)
couldnt you also put an updateAfterEvent() at the end of myFunc? I ran your code with 1fps in the swf, and 25fps on the setInterval, but the screen still updated at 1fps. using updateAfterEvent made things a little smootherQuote:
Originally posted by SaphuA
AS
You can, instead, also increase the real framerate of the movie (25 or something). This way the drawings will be refreshed more often, and thus will look smoother.
SaphuA