Timer based Vs frame based

Some days ago I received a message from MaxManning about Summer Couples, and I want you to read it:

« Hey, first I love your new game Summer Couples, it’s wasted far more of my time than I should have allowed it to. That’s the sign of a good game!

Anyways, I was playing it when I had a pretty intensive flash game running in another tab in Firefox. I didn’t notice until about 3-4 minutes in the game, but it seemed like the game wasn’t really getting harder. I then noticed that the timer bar was going much slower than what I might have expected at that point in the game.

At first I figured maybe you had uploaded a new version of the game that was a bit easier - possibly because someone had said it was too hard. So, I ended up getting like 60k or something and now have the high score — but now I know that it’s completely based on your timer bar being frame based as opposed to being based on a real timer.

Sorry for the long drawn out message :) But the short versio is - I think switching the timer bar to being time based as opposed to frame based would prevent cheating. »

I have to say… he’s right!

Using frame based (or loop based, or any other way of measurement that does not use the clock) events means your game can be cheated easily.

Just open some CPU expensive software and you will slow down the game, making it easier to play. So people will want to slow down the game.

If you set Timer based events, even if your game is slowed, the timer keeps running at the same rate, and people won’t want to slow down the game.

Thank you MaxManning

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 4 out of 5)
Loading ... Loading ...

9 Responses to “Timer based Vs frame based”

  1. Prankard on August 16th, 2008 12:37 am

    I’m working on a box2d game at the moment. I was having “related” problems in terms of experiencing different speeds of the game for on different computers.

    I always test my games on my friends PC that I built for her, it’s a single core 1Ghz AMD, 512mb RAM and if it runs my game at anywhere near a playable speed I’m happy.

    What I used to do (and other developers used to do) was change the framerate of your game from your standard NTSC 30fps to something nearer 60.
    This way it would force your CPU draining game to try to run faster and actually playable. The problem with this was, browsers (like Safari) began to run flash faster, and with PC’s speeding up in processing power it was possible to actually run the game at 60fps, which is unplayable.

    Now, I’ve come across frameRateKeeper.as which can be found at MajiDesign:
    http://majidesign.com/forum/viewtopic.php?t=46

    What it does is get the data from the system clock and monitor how fast your flash is running (actual framerate), then using the new AS3 code change the flash running framerate to speedup or slowdown your flash until you get the desired framerate.

    It’s very simple code and can easily been written directly into your flash (but why re-invent the wheel).

    So, download it and see how it performs in browser and out of browser on your game. If you want to do some test, take out the line that changes the framerate and just monitor what rate it is running at.
    Oh, and please be aware, tracing out a lot of things like frameRateKeeper currently does I wouldn’t do. I only have a single core on my laptop and tracing lots of things causes my flash to run a lot slower. Just display the framerate in a dynamic textbox.

    I hope this post has been useful.

  2. limpeh on August 16th, 2008 12:58 am

    However, if you make it timer-based, then that will not be fair for those people with slower computer, am I right? That means, they have slower ‘responding time’ but the time just keeps on passing.

  3. rob on August 16th, 2008 2:35 am

    perhaps you could monitor the frame rate and stop the game if it drops below a certain level

  4. Kesh on August 16th, 2008 8:33 am

    so limpeh, you are trying to say that he should enable an easy cheat just because there are 80 year olds with pieces of shiz computers?

  5. Livesinabox on August 16th, 2008 11:55 am

    It’s a valid point, timing in flash is terrible and the slower your computer is running (if it’s just busy running other apps, old or a cheap laptop running vista) then a lot of flash games become unplayable due to the frame update rate compared to the input reaction speed.

    About the only thing you can do is watch the number of frames going by and average the time across a few seconds and adjust the game accordingly. I use a smoothed frame update method which instead of giving me say 70ms->20ms->40ms gives me 33ms->30ms->31ms which i use for slightly smoother motion and animation. You can see my test on my blog http://www.adventuresinactionscript.com/blog/27-07-2008/accurate-timing-with-actionscript-3

    Until adobe improve their timing under all circumstances (which is probably very difficult) you’ll struggle to get accurate timing - although i do have some other ideas, i haven’t had time to put them into practice!

    As for cheating - if someone really wants to cheat theres already tools that do this kinda thing which you’ll struggle to protect against - google “speed gear”. Check out youtube for all the videos of people cheating in flash in various ways!

  6. Jhelle on August 16th, 2008 7:48 pm

    I recently stumbled upon a discussion about this topic and within it is a nice explanation on how to make a true timer based function in AS2.0

    https://www.mochiads.com/community/forum/topic/best-way-to-make-slow-motion/54949#54949

  7. Iain on August 17th, 2008 6:21 pm

    You should only ever use a time-based timer if you have time-based game code, for example onUpdate(){x += 5 * timeElapsedSinceLastFrame}

    If you have frame-based game code, for example onUpate(){x += 5} you should be using a frame based timer.

    This is the fairest way to do it. I guess developers (me included) do things frame-based because it’s simpler, and collision detection code etc is easier and more consistent to program. For multi-user games, for example, you have to be time-based, so it’s a useful thing to learn.

  8. Ian Callaghan on September 11th, 2008 2:11 am

    If you think about it though, it really depends on the game. For example if you had a game where you had to last aslong as you could that used a true timer, it could be exploited by using cpu intensive apps to lower the frame rate.

    I guess real time/frame based both have their advantages for different situations =)

Leave a Reply




Trackbacks

  1. Flash tutorials | AS3 Timer class tutorials roundup | Lemlinh.com on September 20th, 2008 6:54 am

    [...] Read more [...]