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.

Playtime HUD

Hey just thought id ask here if anyone can help me tidy up my first script, im pretty sure theres a way easier way of doing it. Some of it is code from the playtime window and I was wondering if there was a way to call the information from that script, instead of duplicating it in mine. Thanks in advance :]

Code:
class Window_PLayTimeHud < Window_Base
  def initialize
    super(0, 0, 210, 64)
    self.contents = Bitmap.new(width-32, height-32)
    self.opacity = 200
    self.contents.clear
  refresh
end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, 120, 32, "Play Time:")
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    hour = @total_sec / 60 / 60
    min = @total_sec / 60 % 60
    sec = @total_sec % 60
    text = sprintf("%02d:%02d:%02d", hour, min, sec)
    self.contents.font.color = normal_color
    self.contents.draw_text(50, 0, 120, 32, text, 2)
  end
  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
end


class Scene_Map
  alias playtimehud_main main
  alias playtimehud_update update
  def main
    @playtimehud = Window_PLayTimeHud.new
    playtimehud_main
    @playtimehud.dispose
  end
  def update
    @playtimehud.update
    playtimehud_update
  end
end
 
Well, you could just do:

Code:
class Your_Class < Window_Playtime

And overwrite the methods of Window_Playtime while not having to overwrite the entire class or something.

Also, I don't understand why you re-wrote a playtime window in the first place when you didn't seem to change much from the original...

But, I can see no problems to your edit of Scene map, except that I think your hud would still be visible when you do things like show a message window.
 
I only wrote it for a bit of practise :P started ruby on thursday morning :] it dissappears when the menu is opened or a battle is started etc ...

You have any ruby scripting tips for me to take heed of ?
 

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