(REQUEST) Timer modification

Hi, I was wondering if anyone know how to input milliseconds in the timer? So it look like this: 03:00:00 (3 minutes)
Easy enough, give me a minute...

Here ya go!

Sprite_Timer+ Spoiler
  1. #==============================================================================
  2. # ** Sprite_Timer
  3. #------------------------------------------------------------------------------
  4. #  This sprite is used to display the timer.It observes the $game_system
  5. #  class and automatically changes sprite conditions.
  6. #==============================================================================
  7.  
  8. class Sprite_Timer < Sprite
  9.   #--------------------------------------------------------------------------
  10.   # * Object Initialization
  11.   #--------------------------------------------------------------------------
  12.   def initialize
  13.     super
  14.     Graphics.frame_rate = 0.01
  15.     self.bitmap = Bitmap.new(132, 48)
  16.     self.bitmap.font.name = "Arial"
  17.     self.bitmap.font.size = 32
  18.     self.x = 640 - self.bitmap.width
  19.     self.y = 0
  20.     self.z = 500
  21.     update
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # * Dispose
  25.   #--------------------------------------------------------------------------
  26.   def dispose
  27.     if self.bitmap != nil
  28.       self.bitmap.dispose
  29.     end
  30.     super
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # * Frame Update
  34.   #--------------------------------------------------------------------------
  35.   def update
  36.     super
  37.     self.visible = $game_system.timer_working
  38.     if $game_system.timer.to_f / 40.0 != @total_sec
  39.       self.bitmap.clear
  40.       @total_sec = $game_system.timer.to_f / 40.0
  41.       min = @total_sec / 60
  42.       sec = @total_sec % 60
  43.       mil = (@total_sec.to_f * 60) % 60
  44.       text = sprintf("%02d:%02d:%02d", min, sec, mil)
  45.       self.bitmap.font.color.set(255, 255, 255)
  46.       self.bitmap.draw_text(self.bitmap.rect, text, 1)
  47.     end
  48.   end
  49. end
Expand to see the code.


On a side note, only if you're interested in knowing... its not really too important, but it doesn't hurt to learn something.

Interesting find about changing Graphics.frame_rate Spoiler
I learned something new upon testing your request. I wanted to actually test the accuracy of the milliseconds, so I changed Graphics.frame_rate from 40 to 20 to 10 to 1 to 0.1, etc you get the idea, just so I could see the actual milliseconds counting down. Keep in mind, I tested the timer set at 1:00 at all times...

Well, as I started changing Graphics.frame_rate, I noticed the lower it was the higher the timer was and visa versa. For instance, Graphics.frame_rate = 20 would make the timer 2:00 instead of 1:00, and Graphics.frame_rate = 80 would make the timer 0:30... that isn't right! Remember how I said I set the timer at 1:00?

RMXP's frame_rate is supposed to always be 40
RMVX's frame_rate is supposed to always be 60

Many anti-lag scripts I've seen change Graphics.frame_rate to try and speed up the game when it is lagging, which is okay and works sometimes but will affect the Timer and possibly Window_Playtime's time. The solution, you can do a CTRL+SHIFT+F and replace anything that references Graphics.frame_rate with 40 (or 60 for VX), and you won't have to worry about Graphics.frame_rate affecting timed-things.


...I thought that was kinda interesting and you might like to know, because I didn't realise that until now either ;)
Thanks alot man :D I've always hated that the timer doesn't show ms, it doesn't give you the feeling that you must hurry. But know it looks so much better.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=65435