Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_PlayTime

Window_PlayTime


Inherits from: Window_Base

Description: This window displays the player's play time in the main menu.

Code


class Window_PlayTime < Window_Base
# ------------------------------------
 def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
# ------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 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(4, 32, 120, 32, text, 2)
  end
# ------------------------------------
  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
end

Properties


Total_Sec: The total amount of seconds the player has been playing.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: This method initializes the window by setting the width of the window to 160, and the height of the window to 96. Note that the y coordinates of 0 is a dummy value. The y coordinate is changed by the Scene_Menu object. The window is then refreshed.

Refresh

Arguments: None
Local Variables: None

How it Works: This method draws the window's contents. The first thing the method does is clear the window's contents. The words "Play Time" are drawn in the system color at x coordinate 4 and y coordinate 0. Next, the value of @total_sec is set to the value of Graphics.frame_count (the total number of frames shown since the beginning of the game) divided by the current frame rate. The next three statements divide the value of @total_sec into hours, minutes, and seconds. The number of hours played is the total number of seconds divided by 3600. The number of minutes played is the total number of seconds divided by 60, then modded by 60. Finally, the seconds to be shown is the total number of seconds modded by 60. Once these three values are computed, the text = sprintf("%02d:%02d:%02d", hour, min, sec) statement formats the three values into a string, with each of the three values seperated by the ":" character. The next two statements print the formatted string at x coordinate 4 and y coordinate 32.

Update

Arguments: None
Local Variables: None

How it Works: This method updates the window. It first calls the superclass method in order to perform updating common to all windows. If the value of Graphics.frame_count (the total number of frames shown since the beginning of the game) divided by the number of frames per second is not equal to the value of @total_sec, then the window is refreshed to reflect the proper play time. Note that because of this, drastic changes in the frame rate will cause the play time shown to be incorrect. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal