Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

(REQUEST) Timer modification

Easy enough, give me a minute...

Here ya go!

Code:
#==============================================================================

# ** Sprite_Timer

#------------------------------------------------------------------------------

#  This sprite is used to display the timer.It observes the $game_system

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Sprite_Timer < Sprite

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super

    Graphics.frame_rate = 0.01

    self.bitmap = Bitmap.new(132, 48)

    self.bitmap.font.name = "Arial"

    self.bitmap.font.size = 32

    self.x = 640 - self.bitmap.width

    self.y = 0

    self.z = 500

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    if self.bitmap != nil

      self.bitmap.dispose

    end

    super

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    self.visible = $game_system.timer_working

    if $game_system.timer.to_f / 40.0 != @total_sec

      self.bitmap.clear

      @total_sec = $game_system.timer.to_f / 40.0

      min = @total_sec / 60

      sec = @total_sec % 60

      mil = (@total_sec.to_f * 60) % 60

      text = sprintf("%02d:%02d:%02d", min, sec, mil)

      self.bitmap.font.color.set(255, 255, 255)

      self.bitmap.draw_text(self.bitmap.rect, text, 1)

    end

  end

end

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

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 ;)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top