A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] Loops and Framerates

  1. #1
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270

    [F8] Loops and Framerates

    Hey everybody,

    Johnny Blazed was asking about some framerate issues he was having with his Snake 2 game recently and I've run into some snags myself after a couple short tests.

    I have a background in VB (try not to laugh too hard.) In VB, there is a way to request a timeout from within a loop so that the application does not become unresponsive. This was done by calling the DoEvents function at the end of the statement block of the loop.

    The idea: I would like to use a "do ... while" for the main process of my game such that I can achieve a high resolution interval from which I can arrive at different framerates for certain kinds of animated elements that are on screen at the same time. For instance, a quickly flickering candle and a slowly waving flag.
    The catch: the movie becomes unreponsive because the "do ... while" hogs the cpu.

    Is there a way to force a "do ... while" loop in ActionScript to function in a similar way to DoEvents without canceling the loop entirely by using the break statement?
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  2. #2
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    After some quick tests, I've decided to use a "for" loop with ten iterations inside of an onEnterFrame() handler. The document framerate is set to 60 and does not show any signs of slowdown even when manipulating large images. I expect the performance to go down significantly as more things are drawn to the screen at any given time, but hopefully cacheAsBitmap() will be able to take most of the heat off.

    My only concern is that this method of achieving high resolution timing is still dependent upon the playback speed of the movie and therefore subject to the hardware limitations of the local machine. How much of an Achilles Heel is this?
    Last edited by Q__Hybrid; 01-24-2007 at 09:59 PM.
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    60 can be quite high if on low cpu machines. But the question is more: is 60 a steady fps?
    I think you should test different speeds with (custom) fps counters. For example, I noticed that 31 is more stable than 30.
    The good thing about intervals is that you can clear them if they are not needed and reset them again when needed. same with enterFrame that can be deleted or set to null or undefined.

    One last thing, that you may already know, is the use of (silent or not) streamed sounds that ensure steady fps rates.

    gparis

  4. #4
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    The greater stability of 31 fps as opposed to 30 fps actually makes alot of sense, considering it's a power of 2 (and a binary place value, where 0 = 1.)

    I'm testing my movie on an older machine, a Vaio PCG-FX220. I believe it has a Pentium 3 at about 750MHz and 128 RAM. I'm aiming low when it comes to the hardware I develop on, besides, this machine has been with me through alot.

    After loading up a rather sizable image (approx. 900 x 1050), I did notice some lag when the movie was fullscreened during testing. Luckily, my project is going to be sized to 320 x 240. Windowing the test at that size lets it run blazingly fast.

    I don't know if I should start another thread for this, and this entire discussion probably belongs in the Games category, but how quickly can cacheAsBitmap() be called? I would, ideally, like to use a stack of cached bitmaps to render each frame (one for backdrop, one for objects, one for players, and so on) if possible.

    This is partially the reason for requiring a very high resolution of elapsed time. It will be necessary in some cases to setup each frame element for caching within a very short period of time.

    I do not see any advantage to using setInterval because the ease of deleting or assigning an intervalID could be easily developed to work with my current proposed system. Also, setInterval() appears to have far too great of a downside to be well-suited to my plans.

    Any early suggestions and considerations are welcome.
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    how quickly can cacheAsBitmap() be called? I would, ideally, like to use a stack of cached bitmaps to render each frame (one for backdrop, one for objects, one for players, and so on) if possible.
    Quicker if your bitmaps are on whole coordinates.

    gparis

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