A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Is there any way to change the FPS by code?

  1. #1
    Senior Member
    Join Date
    Jun 2005
    Posts
    203

    Is there any way to change the FPS by code?

    just wondering

  2. #2
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Nope. Not unless u have made your game fps dependant. Like run a piece of code every 4 frames. ie: Have a movie clip, inside that movie clip: Frame 1-3 = empty, frame 4 has the code like gotoandplay(1), then it will be running at 4fps, or when u want it go faster, change it to 3, that is make it run fast cuz it will be looping between frame 3 and 4. You just have to make the (1) a variable so u can change it in the game while it's running.

    Btw,, didn't think while writing this.......... back to world of warcraft...

  3. #3
    Senior Member
    Join Date
    Jun 2005
    Posts
    203
    nah, I was talking about changing the actually fps cause in some games, you need to have a high frame-rate for it to run good, but then animating cutscenes and crap becomes a pain in the ass. Oh well, guess I can always double frame

  4. #4
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Hmm....Iam guessing that setInterval() might do what you want. You can have the cutscene animation in a mc. In the first frame of the mc the code can be this:-

    Code:
    //animation's current frame
    var currframe = 1;
    function movemovie() { 
            this.gotoAndStop(currframe);
            currframe++;
    }
    var intervalID; 
    // change the 1000 with the fps speed you like, 1000 means 1 second
    intervalID = setInterval( movemovie, 1000 );
    Code:
    // on the last frame of the movie clip
    clearInterval( intervalID );
    Have'nt tried it, just outta my mind.

    edit:syntax errors
    Last edited by adit_ya_sharma; 07-07-2005 at 10:00 AM.
    -Aditya

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Posts
    101

    tis possible

    ooo, looks like i accidently posted half way through writing
    Last edited by PercyPea; 07-07-2005 at 08:55 AM.

  6. #6
    Senior Member
    Join Date
    Aug 2001
    Posts
    101

    tis possible

    tis actually indeed possible.

    but this method isnt very acurate if you want to jump between higher frame rates, ie 20fps+

    First thing is to set your flash movie to publish at the maximum frame rate you want anything to run at.

    Ie, if you want the fastest parts of the game to run at 40fps, set your frame rate to that

    Then, in a new layer that lasts the length of your flash movie, stick in a movieclip.

    On the first frame of the movie clip, place this code:-

    Code:
    starttime = newDate()
    onEnterFrame=function(){
       var currtime=new Date()
       var ttime=currtime-starttime
       while(ttime<1000/DESIREDFRAMERATE){
          var currtime = new Date()
          var ttime=currtime-starttime
       }
       starttime=new Date()
    }
    Wher it has 'DESIREDFRAMERATE' simply change this to be the frame rate you want to make the movie at.

    Apart from a few values in the high teens, this code will allow you to change the framerate of the movie to any fps from 1 to 12.

    You will also be able to set the framerate faster, up to the 40 (or whatever you publish the movie at) but due to the way flash works, it wont be as accurate.

    Ie, if you put in both 13 or 14 as the 'DESIREDFRAMERATE', the movie would run at the same speed.

    15 and 16 are also the same. 17, 18 and 19 will give the same.

    As you get higher, you will find more values give the same rate. 20-24 are the same, 25 - 33 are the same. If you tell flash to publish the movie at the maximum of 120fps, you'll find that settingthe 'DESIREDFRAMERATE' between 34 - 49 will be the same framerate, setting it to 50 - 99 same, 100-120 also the same.

    The reason why you get less accurate changes as you try for higher frame rates, is because flash seems to have to take factors of 0.01 seconds to run the code on the 'onEnterFrame' bit.

    To have a frame rate of 80fps, you'd need every frame to last for exactly 0.0125 seconds, but flash wont let that happen, so by putting in 80, you get it rounded up to the nearest 0.01. So each frame actually lasts 0.02 seconds, which means you get a 50fps movie.


    anyhow, attached is a basic example using the code above.

    The value on the left is editable, the value on the right shows how long the ball takes to bounce in milliseconds. The animation of the ball is 18 frames, so you can see that the time changes at intervals of 180ms per bounce. (0.01 seconds per frame).

    The movie is published at 120fps.

    A more practical method of the code can also be found in this GTA tech demo.

    http://www.percypea.co.uk/gta

    the game will either try to run at the maximum of 120fps (depending on the speed of your computer) or you can limit it to 25fps by clicking the white button on the left of the fps counter.
    Attached Files Attached Files

  7. #7
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Like adit ya sharma said.. but I didnt explain it codewise or good, was lazy and was playing a game.... .... but set interval is the way to go.

    nah, I was talking about changing the actually fps cause in some games, you need to have a high frame-rate for it to run good, but then animating cutscenes and crap becomes a pain in the ass. Oh well, guess I can always double frame
    The actual frames of Flash cannot be changed, so the only way is to code your game in a certain way, like above adit told you.
    Last edited by Ironclaw; 07-07-2005 at 10:40 AM.

  8. #8
    Senior Member
    Join Date
    Jun 2005
    Posts
    203
    Quote Originally Posted by PercyPea
    tis actually indeed possible.

    but this method isnt very acurate if you want to jump between higher frame rates, ie 20fps+

    First thing is to set your flash movie to publish at the maximum frame rate you want anything to run at.

    Ie, if you want the fastest parts of the game to run at 40fps, set your frame rate to that

    Then, in a new layer that lasts the length of your flash movie, stick in a movieclip.

    On the first frame of the movie clip, place this code:-

    Code:
    starttime = newDate()
    onEnterFrame=function(){
       var currtime=new Date()
       var ttime=currtime-starttime
       while(ttime<1000/DESIREDFRAMERATE){
          var currtime = new Date()
          var ttime=currtime-starttime
       }
       starttime=new Date()
    }
    Wher it has 'DESIREDFRAMERATE' simply change this to be the frame rate you want to make the movie at.

    Apart from a few values in the high teens, this code will allow you to change the framerate of the movie to any fps from 1 to 12.

    You will also be able to set the framerate faster, up to the 40 (or whatever you publish the movie at) but due to the way flash works, it wont be as accurate.

    Ie, if you put in both 13 or 14 as the 'DESIREDFRAMERATE', the movie would run at the same speed.

    15 and 16 are also the same. 17, 18 and 19 will give the same.

    As you get higher, you will find more values give the same rate. 20-24 are the same, 25 - 33 are the same. If you tell flash to publish the movie at the maximum of 120fps, you'll find that settingthe 'DESIREDFRAMERATE' between 34 - 49 will be the same framerate, setting it to 50 - 99 same, 100-120 also the same.

    The reason why you get less accurate changes as you try for higher frame rates, is because flash seems to have to take factors of 0.01 seconds to run the code on the 'onEnterFrame' bit.

    To have a frame rate of 80fps, you'd need every frame to last for exactly 0.0125 seconds, but flash wont let that happen, so by putting in 80, you get it rounded up to the nearest 0.01. So each frame actually lasts 0.02 seconds, which means you get a 50fps movie.


    anyhow, attached is a basic example using the code above.

    The value on the left is editable, the value on the right shows how long the ball takes to bounce in milliseconds. The animation of the ball is 18 frames, so you can see that the time changes at intervals of 180ms per bounce. (0.01 seconds per frame).

    The movie is published at 120fps.

    A more practical method of the code can also be found in this GTA tech demo.

    http://www.percypea.co.uk/gta

    the game will either try to run at the maximum of 120fps (depending on the speed of your computer) or you can limit it to 25fps by clicking the white button on the left of the fps counter.
    thanks! Thats awsome. BTW, how did you get your gta game to have 3d buildings? Is there any way you can combine that with a mode7 engine?

  9. #9
    Junior Member
    Join Date
    Jan 2008
    Posts
    1

    do you have the .fla

    Hi, I can't quite get this to work, do you have the .fla and could you send it or upload it?

    (I use flash MX 2004)

    Thankyou.

  10. #10
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    In CS3 with AS3 this is as easy as changing the Stage.frameRate property. I'm using it as we speak and it works great. There are better ways though as describe above, but this does indeed change the running framerate of main timeline.

    -Jeff

  11. #11
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    hey guys the last post here was posted 07-08-2005, 12:36 AM, a little bit old dont you think?

  12. #12
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    That's hilarious! I just saw it at the top of the list and started replying!

  13. #13
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    well I guess I meant rather the other one,- anyway to contribute a little bit too:
    independent movement is the key anyway- just set your framerate to the maximum you want (dont overdo, 120 fps is the limit anyway) and write a tween function that returns you the value depending on what time it starts, ends and home much already elapsed.
    If you use the tween class for example (works with flash player 7+) you can pass a var saying that it should be time dependent or frames but framewise it´s not always accurate as the performance can different.

  14. #14
    Member
    Join Date
    Nov 2003
    Location
    Southampton, UK
    Posts
    48

    thanks!

    big thanks to percy pea for the code, i just spent hours looking for a way to slow down a movieclip's frame rate.

    you made my day!

    grete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center