How do I make 1 minute always last 1 minute

0 favourites
  • 13 posts
From the Asset Store
12 looping retro style music tracks for your indie games and projects
  • Hi, im still having some issues with time and performance, i have a game that lets you play for a minute or till you find all the hidden objects in a stage, score is calculated as (time)*100, scores are saved to a DB via Ajax.

    The maximum possible score is 6000 and that means that you found 6 objects before 1 millisecond passed.

    I've tried a few different implementations of the time and always end up having the same issue, users with really slow PCs have their time ticking slower that it is supposed to.

    Im getting times like 5980, that are obviously impossible to achive saved to DB and most of those users when asked reported having really crappy PCs.

    My current implementation of the timer is in the attached img.

    Thanks in advance!

  • You should use delta time for this (dt) :

    https://www.scirra.com/tutorials/67/del ... dependence

    Start your timer at 60, every tick subtract dt from timer. It will always last 60 seconds.

  • Thanks for the reply Joskin, i was told in a previous post that dt should not be used for timing as it's meant to be used only for movement.

    Now im confused hehehe.

  • Ah, weird, usually in development even for timer you will use delta time. I'm using dt for timers in my game and I have no problem.

    We need another point of view !

  • In my old thread () another user suggested dt is the way to go.

    We could really use an official opinion about this issue.

    Thanks!

  • Use dt, everybody use dt for time management.

  • dt (deltatime) is the time (in second in c2) elapsed between the previous frame and the current.

    So if you accumulate them you'll reach 1 in one second.

    If you run at 60 fps (frame per second), the time between two frame is about 0.016s (1/60)

    So after 60 frames, 1 second will have elapsed and you would have acumulated 60 * dt = 60 * 1/60 = 1.

  • I would set a variable at the start of the loop to wallClock and then ever x seconds (or tenths of a second) compare the "now time" against this stored time. This way you should get a very accurate time.

  • not really sure if the problem is about dt or using time, time should have the same accuracy as dt, No?

    maybe some slight difference in your logic, ... or they are cheating somehow..

  • That's how I would implement your system

    hiddenObjectClock.capx

    dt and time have the same accuracy, as time is internally computed by adding dt to it each frame.

  • I agree that in 99.9% of cases adding dt every tick to a counter will give you an accurate time - but , if I understand it correctly, if your fps drops below 10 fps then dt will not work any more as dt is not allowed to go above 0.1 so your timer will start to slow. I don't think very low fps affects the time/wallclock ?

  • I love your implementation Yann, im going to use that, with an added control to pause the game if the fps drops below 10, as RamPackWobble said dt will not go below 0.1 and i think there is where the problem is.

    I have to read the manual about the system functions of C2, i didn't know some of those even existed.

    vtrix, yeah i think most are cheating, maybe using something like cheat engine to modifiy the timers or just stop the clock.

    For the next implementation i'm going to do some research on ways to prevent that, i already have a lot of security measures in place to avoid "fake" post request to the server, currently the scores and all sensitive data is encoded in AES256 before it gets send to the server and the score is "masked" behind a few maths operations.

    Thanks everyone, especially Jann and RamPackWobble!

    Great community support as always.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • RamPackWobble you do have a point here, I noticed going through c2's javascript that dt was clamped to 0.1

    It's a common technique to avoid object teleportation. But yeah in sinneruy's specific case it might be detrimental.

    I modified the capx to compute my own dt using wallclocktime. It should counter this issue.

    hiddenObjectClock.capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)