Timer Rewrite
+4
crazedanimekid
Light
Dezz123
Kyle?
8 posters
OmegaDev :: Coding Plaza :: RGSS2 (VX)
Page 1 of 1
Timer Rewrite
Ok this enables you to change the X, Y of the timer adn it's font to fit you games to!
There are 2 Versions I have one were you can change the Font
And one that works with your defualt font:
So
There are 2 Versions I have one were you can change the Font
- Spoiler:
- Code:
#==============================================================================
# Timer Rewrite
# By Kyle?
#----------------------------------------------------------------------------
module Timer
module Kyle
Font_Name = "Arial"
Timer_X = 544
Timer_Y = 0
end
end
#==============================================================================#
$imported = {} if $imported == nil # <- DON'T TOUCH!!
$imported["TimerRewrite"] = true # <- DON'T TOUCH!!
#==============================================================================#
class Sprite_Timer < Sprite
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
self.bitmap = Bitmap.new(88, 48)
self.bitmap.font.name = Timer::Kyle::Font_Name
self.bitmap.font.size = 32
self.x = Timer::Kyle::Timer_X - self.bitmap.width
self.y = Timer::Kyle::Timer_Y
self.z = 200
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.visible = $game_system.timer_working
if $game_system.timer / Graphics.frame_rate != @total_sec
self.bitmap.clear
@total_sec = $game_system.timer / Graphics.frame_rate
min = @total_sec / 60
sec = @total_sec % 60
text = sprintf("%02d:%02d", min, sec)
self.bitmap.font.color.set(255, 255, 255)
self.bitmap.draw_text(self.bitmap.rect, text, 1)
end
end
end
And one that works with your defualt font:
- Spoiler:
- Code:
#==============================================================================
# Timer Rewrite
# By Kyle?
#----------------------------------------------------------------------------
module Timer
module Kyle
Timer_X = 544
Timer_Y = 0
end
end
#==============================================================================#
$imported = {} if $imported == nil # <- DON'T TOUCH!!
$imported["TimerRewrite"] = true # <- DON'T TOUCH!!
#==============================================================================#
class Sprite_Timer < Sprite
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
self.bitmap = Bitmap.new(88, 48)
self.bitmap.font.name = Font.default_name
self.bitmap.font.size = 32
self.x = Timer::Kyle::Timer_X - self.bitmap.width
self.y = Timer::Kyle::Timer_Y
self.z = 200
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.visible = $game_system.timer_working
if $game_system.timer / Graphics.frame_rate != @total_sec
self.bitmap.clear
@total_sec = $game_system.timer / Graphics.frame_rate
min = @total_sec / 60
sec = @total_sec % 60
text = sprintf("%02d:%02d", min, sec)
self.bitmap.font.color.set(255, 255, 255)
self.bitmap.draw_text(self.bitmap.rect, text, 1)
end
end
end
So
Kyle?- Platinum Cookiez
- Posts : 500
Gald : 418
Stats
Cookies: 5
Re: Timer Rewrite
I like it. Thumbs up Kyle.
crazedanimekid- Platinum Cookiez
- Posts : 501
Gald : 1277
Stats
Cookies: 0
Re: Timer Rewrite
Nice, although possibly give the option of having it left alligned or right alligned?
And you don't need to include the update and dispose methods. It's probably better if you don't.
And you don't need to include the update and dispose methods. It's probably better if you don't.
IMP1- Coding Moderator
- Posts : 503
Gald : 1399
Stats
Cookies: 5
Re: Timer Rewrite
Nice one, even if I never use timers xD
Vectomon- Resource Moderator
- Posts : 1029
Gald : 3025
Stats
Cookies: 0
Re: Timer Rewrite
I never really ran into any events that came to need a timer. But if that should happen, I will be sure to give this a try.
moneymenace- Resource Moderator
- Posts : 538
Gald : 1337
Stats
Cookies: 0
Re: Timer Rewrite
From a coder's point of view, this is a bit sloppy.
You overwrite the entire class (2 of the methods unnecessarily) when an alias to the update method will work completely with 0 compatibility issues.
You also have 2 versions when only 1 is needed Just have them put the default font in the configuration if they want to use it.
Something more along the lines of this will work:
You overwrite the entire class (2 of the methods unnecessarily) when an alias to the update method will work completely with 0 compatibility issues.
You also have 2 versions when only 1 is needed Just have them put the default font in the configuration if they want to use it.
Something more along the lines of this will work:
- Spoiler:
- Code:
module Timer
module Kyle
Font_Name = "Arial"
Timer_X = 544
Timer_Y = 0
end
end
$imported = {} if $imported == nil # Creates a hash if the global variable is not created yet.
$imported["TimerRewrite"] = true # Makes the key "TimerWrite" have the value of true.
class Sprite_Timer
include Timer::Kyle # Includes the constants of the module Kyle inside the module Timer.
alias jet3782_update update unless $@ # This stores the previous defintion of update into a new defintion of jet3782_update unless already defined.
def update # overwriting update to call the aliased update, plus additions.
self.x = Timer_X unless self.x == Timer_X or !$game_system.timer_working # change the timer's x to the constant unless it already is equal to the constant or the timer is invisible.
self.y = Timer_Y unless self.y == Timer_Y or !$game_system.timer_working # change the timer's y to the constant unless it already is equal to the constant or the timer is invisible.
self.bitmap.font.name = Font_Name unless self.bitmap.font.name == Font_Name # Change the font 1 time only.
jet3782_update # Call the old update method.
end
end
Jet- Newcomer
- Posts : 13
Gald : 91
Stats
Cookies: 0
OmegaDev :: Coding Plaza :: RGSS2 (VX)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum