A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: change frame rate while running the swf

  1. #1
    Junior Member
    Join Date
    Jan 2005
    Posts
    10

    change frame rate while running the swf

    can I change frame rate while running the swf?I think its useful, but...

    Thanks!

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Fraid not mate.

    There are cheaty kludgy ways of faking it using setInterval, but it's less than ideal.

    Squize.

  3. #3
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    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
    Last edited by SaphuA; 02-05-2005 at 06:55 AM.

  4. #4
    Junior Member
    Join Date
    Jan 2005
    Posts
    10
    Thanks for Squize and SaphuA's help,
    especially for SaphuA's code :-)

    I love here.

  5. #5
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    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....
    -Aditya

  6. #6
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    it's not a brilliant way to do things, but you could reload a base level which determines the global fps (attached)

  7. #7
    Shenanigans JimmyDinner's Avatar
    Join Date
    Mar 2003
    Location
    Vancouver
    Posts
    175
    Originally posted by SaphuA
    AS
    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 smoother

  8. #8
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    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

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