Thread: reset time after some interval

  1. #1
    Registered User
    Join Date
    Apr 2014

    Talking reset time after some interval

    Hello, I working on a game in SDL. I want to reset the timer in every 15 seconds or so. I have tried SDL_GetTicks() but it works fine for first time after that time goes in -tive.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    SDL_GetTicks - SDL Documentation Wiki
    How can it be negative when it returns an unsigned number?

    Rather than trying to reset the system tick count (which you're not likely to be able to do, or if you can, there will be consequences), write your own simple wrapper class.

    Something like
    class myclock {
        Uint32 base;
        myclock() { base = SDL_GetTicks(); }
        reset() { base = SDL_GetTicks(); }
        UInt32 elapsed() { return SDL_GetTicks() - base; }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sin(x) aproximmation and 2π Interval [-π,π]
    By aggeluska in forum C Programming
    Replies: 5
    Last Post: 11-18-2013, 06:08 PM
  2. Running a procedure repeatedly after a set time interval
    By workisnotfun in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2013, 10:57 PM
  3. Is there a way to reset the bash or zsh idle time?
    By Overworked_PhD in forum Linux Programming
    Replies: 3
    Last Post: 04-06-2009, 09:02 AM
  4. rand interval
    By jarheadhalo in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2006, 01:07 PM
  5. Replies: 2
    Last Post: 02-28-2002, 12:40 PM

Tags for this Thread