RadethDart
Sponsor
I made a HUD for my game, and it is causing MAJOR lag, without it I run 40 FPS, and with it, I run 4 FPS...could someone help and see what I did wrong to make it lag like this.
Here is the HUD, and please, don't take this and claim it as your own thanks!
Here is the HUD, and please, don't take this and claim it as your own thanks!
Code:
#------------------------------------------------------
# Shifter HUD
# v 1.0
# Author - Joshua Long
# This HUD is made for Shifter.
#------------------------------------------------------
class Window_hud < Window_Base
def initialize
super(-10, -10, 650, 650)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Arial"
self.contents.font.size = 15
self.back_opacity = 0
refresh
end
def refresh
self.contents.clear
reset_variables
return if !@actor
draw_actor_graphic(@actor, 18, 58)
draw_bar(63, 70, @actor.sp, @actor.maxsp, 90, 8, Color.new(88, 200, 244, 255), Color.new(0, 56, 200, 255))
self.contents.draw_text(0, 48, 120, 32, "Stamina: " + $game_party.actors[0].sp.to_s + " / " + $game_party.actors[0].maxsp.to_s)
draw_actor_name(@actor, 0, -10.5)
self.contents.draw_text(40, 0, 92, 32, "Strength: " +$game_party.actors[0].str.to_s)
self.contents.draw_text(40, 12, 92, 32, "Agility: " +$game_party.actors[0].agi.to_s)
self.contents.draw_text(40, 24, 92, 32, "Intelligence: " +$game_party.actors[0].int.to_s)
self.contents.draw_text(40, 36, 92, 32, "Dexterity: " +$game_party.actors[0].dex.to_s)
end
def reset_variables
@actor = $game_party.actors[0]
@oldsp = @actor ? @actor.sp : 0
@oldmaxsp = @actor ? @actor.maxsp : 0
@str = @actor ? @actor.str : 0
@agi = @actor ? @actor.agi : 0
@int = @actor ? @actor.int : 0
@eva = @actor ? @actor.dex : 0
end
def update
@actor = $game_party.actors[0]
@oldsp = @actor ? @actor.sp : 0
@oldmaxsp = @actor ? @actor.maxsp : 0
@str = @actor ? @actor.str : 0
@agi = @actor ? @actor.agi : 0
@int = @actor ? @actor.int : 0
@eva = @actor ? @actor.dex : 0
refresh
end
end
class Scene_Map
alias hud_main main
alias hud_update update
def main
@hud = Window_hud.new
hud_main
@hud.dispose
end
def update
@hud.update
hud_update
end
end
#================================================= =============================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#================================================= =============================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Slant Bar
#--------------------------------------------------------------------------
def draw_bar(x, y, min, max, width = 152, height = 6,
bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
# Draw Border
for i in 0..height
self.contents.fill_rect(x, y + height - i, width, 1, Color.new(50, 50, 50, 255))
end
# Draw Background
for i in 1..(height - 1)
r = 100 * (height - i) / height + 0 * i / height
g = 100 * (height - i) / height + 0 * i / height
b = 100 * (height - i) / height + 0 * i / height
a = 255 * (height - i) / height + 255 * i / height
self.contents.fill_rect(x, y + height - i, width, 1, Color.new(r, b, g, a))
end
# Draws Bar
for i in 1..( (min / max.to_f) * width - 1)
for j in 1..(height - 1)
r = bar_color.red * (width - i) / width + end_color.red * i / width
g = bar_color.green * (width - i) / width + end_color.green * i / width
b = bar_color.blue * (width - i) / width + end_color.blue * i / width
a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
self.contents.fill_rect(x + i - 1, y + height - j, 1, 1, Color.new(r, g, b, a))
end
end
end
end