Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Another way to give Timer property?
- - By kuehkookies Date 2012-10-29 05:18
To the point, is there a way to make a dynamic timer based on FPS? Timer from Chingu often misses some crucial lines in my game (jump distance, attacking delays, etc)...
Or maybe there's another way that better but still using timer method from Chingu?

Thanks in advance.
Parent - - By lol_o2 Date 2012-10-29 14:17 Edited 2012-10-29 14:23
You can just make a global variable and increment it at beginning of every Window.update

class YourWindow
  def initialize
    ...
    $time = 0
  end

  def update
    $time += 1
    ...
  end

  ...
end

I use it in all my games and it proves itself in many situations.
But if by dynamic timer you mean something you can reset and start over, you can add:

@timer ||= $time
if $time == @timer + your_time
  @timer = nil
  ...
end
Parent - By kuehkookies Date 2012-10-29 17:20
Okay. Figured it. That's pretty neat when just implemented in my game. Cheers!
And even I can make a event-handler for timers. (I've figured how to handle timers to get the event switch, but returns nil :p )

Now, I'm replacing timers with frame-based one rather than built-in millisecond-based.
Thanks!
Up Topic Gosu / Gosu Exchange / Another way to give Timer property?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill