A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Game optimisation - updateAfterEvent

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    Game optimisation - updateAfterEvent

    Hello,

    I read in a tutorial, that it is a good idea, to have flash running at 30fps, and haveing a timer that runs at 40fps that does:
    PHP Code:
    function timerhandler(e:TimerEvent)
    {
    e.updateAfterEvent();

    I don't know why, but it seems to save about 10 fps in his example, over just setting the fps to 60. he gets 40fps with this updateAfterEvent, instead of 30fps, when setting the fps to 60, that the comp can't handle.

    now first of all: Why does this help?

    second of all: I have a variety of spaceships in my game, that move at completely different speeds. some go so slow, that you wouldn't notice the difference between 20fps and 60 fps, unless you study them accurately.
    I figured, it woiuld be a good idea to render those slow spaceShips at lower fps, than the fast ones, for optimisation.
    is there a way to set fps for them lower?

    or maybe setting the movementTimer to a higher delay, will have the same effect? because they dont have to be redrawn, untill they move again?
    will this have the same effect in optimisation?

    thank you.
    Last edited by omniscient232; 03-07-2009 at 04:04 AM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I have not seen any proof that using timer would improve fps.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    http://www.8bitrocket.com/newsdispla...newspage=10248,

    but my most concern are the other questions.

  4. #4
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    It's not just that it is a timer and the e.updateAfterEvent is fired off. There certainly are other ways to make a timer/optimized FPS. My timer is based around the concept of sleep and active rendering. By sleep/active rendering I am timing how long the actual game loops takes and then letting the processor sleep before it starts up the game loop again. This is much easier to accomplish in Java with threading (where I got the idea from). This, combined with the e.updateAfterEvent does a good job of smoothing out the framerate.

    BUT, at frame rates above 40, the updateAfterEvent seems to cause some problems on some platforms and players. For that reason, the sleep based/active render game loop can be used without the updateAfterEvent.

    Anyway, it is better to set the delta x and delta y of the different ships to different values rather than trying to run them at different framerates.

  5. #5
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    8bitjeff, what you're talking about sounds really cool...can you please explain maybe a teensy bit more so I can steal your idea?
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  6. #6
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    Hey Pazil, I was referring to the link to my tutorial on Active rendering that Omniscient232 had posted:

    Link

    The idea centers around starting the timer with just 1 repetition (not a constant loop). You time the amount of milliseconds that it takes to run your game loop. If you have not used up all of the time available to the processor, it sleeps and lets to Flash player do things like garbage collection (well it does in Java at least). Then you start the timer again when you wait for the sleep time to finish.

    All of the code and a lively discussion on some problems are fixes are in that above link.

  7. #7
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Good stuff!

    I never knew about bitmapData locking/unlocking. In fact, I never even used bitmapData's (though I will be soon, as soon as I start making a game with my OpenFL library (it sucks right now though...)

    Thanks! I'll give the article another read later. Right now I need to figure out some basic physics so that I can have a nice collision detection engine up'n'running!

    P.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  8. #8
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    what do you mean change delta x and delta y? you mean the hspeed and vspeed?
    i have differend hspeed and vspeed per enemytype. hspeed and vspeed means pixels change per second, in my app. i can then change the timerdelay of every ship.

    I dont have one game loop,that does everything. i have a steptimer, for every ship. and by changing that stepTimer's delay I can choose the rate at which their x and y coordinates are changed.

    This isn't very efficient is it?

    Is it worth doing a redesign because of this? I think that graphics rendering is the bottleneck in my game right now.

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