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.

[Resolved] HUD Taking too long to update...?

Could someone tell me how to make my HUD update as soon as something is changed? It only changes when the time is updated, how can I do this?

EDIT: I FIXED THAT, now my character takes a few steps, then stops for like half a sec, then keeps going, is there a way to make it so that she walks normally?

Here is the script, and please, no one try to steal it  :dead:.
Code:
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# Shifter HUD 
# v 1.0
# Author - Joshua Long
# This HUD is made for Shifter.
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
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
class Window_hud < Window_Base
  def initialize
    super(-10, -10, 700, 700)
    self.contents = Bitmap.new(750 - 32, 750 - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 16
    self.back_opacity = 0
    self.opacity = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Game Time
  #--------------------------------------------------------------------------
  def game_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)
    return text
  end
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# Defines what goes into the hud
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    @oldsp = @actor ? @actor.sp : 0
    @oldmaxsp = @actor ? @actor.maxsp : 0
    @oldhp = @actor ? @actor.hp : 0
    @oldmaxhp = @actor ? @actor.maxhp : 0
    @str = @actor ? @actor.str : 0
    @agi = @actor ? @actor.agi : 0
    @int = @actor ? @actor.int : 0
    @dex = @actor ? @actor.dex : 0
    @time = game_time
    @time = $kts.time.to_s if $kts != nil
    return if !@actor
    bitmap = RPG::Cache.picture("hud")
    self.contents.blt(-5, -5, bitmap, Rect.new(0, 0, 640, 480))
    draw_bar(10, 460, @actor.sp, @actor.maxsp, 125, 10, Color.new(170, 170, 0, 255), Color.new(235, 230, 0, 255))
    draw_bar(10, 440, @actor.hp, @actor.maxhp, 125, 10, Color.new(0, 175, 0, 255), Color.new(0, 73, 0, 255))
    self.contents.draw_text(15, 445, 120, 32, "Stamina: " +$game_party.actors[0].sp.to_s + "/" +$game_party.actors[0].maxsp.to_s)
    self.contents.draw_text(15, 425, 120, 32, "Health: " +$game_party.actors[0].hp.to_s + "/" +$game_party.actors[0].maxhp.to_s)
    draw_actor_name(@actor, 585, 0)
    self.contents.draw_text(5, 20, 100, 32, "Strength: " +$game_party.actors[0].str.to_s)
    self.contents.draw_text(5, 34, 100, 32, "Agility: " +$game_party.actors[0].agi.to_s)
    self.contents.draw_text(5, 48, 100, 32, "Intelligence: " +$game_party.actors[0].int.to_s)
    self.contents.draw_text(5, 62, 100, 32, "Dexterity: " +$game_party.actors[0].dex.to_s)
    self.contents.draw_text(395, 13, 640, 32, $game_party.gold.to_s)
    self.contents.font.color = system_color
    self.contents.font.color = normal_color
    self.contents.font.size = 16
    self.contents.draw_text(100, 20, 640, 32, "Level:")
    self.contents.draw_text(150, 20, 640, 32, @actor.level.to_s)
    draw_actor_graphic(@actor, 600, 75)
    self.contents.draw_text(485, 13, 120, 32, @time.to_s)
    weapon = $data_weapons[$game_party.actors[0].weapon_id]
    unless weapon.nil?
    weapon_name = weapon.name
    weapon_icon = RPG::Cache.icon(weapon.icon_name)
    self.contents.blt(579, 430, weapon_icon, weapon_icon.rect)
    self.contents.draw_text(579, 405, 120, 32, weapon_name)
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    super
    refresh if something_changed?
  end
    def something_changed?
      actor = $game_party.actors[0]
      @actor = $game_party.actors[0]
      return false if Graphics.frame_count % 30 != 0
        return true if Graphics.frame_count / Graphics.frame_rate != @total_sec
        return true if actor != @actor
        return true if @oldsp != @actor.sp or @oldmaxsp != @actor.maxsp  
        return true if @str != @actor.str
        return true if @agi != @actor.agi 
        return true if @int != @actor.int
        return true if @eva != @actor.dex
        return true if @gold_n != $game_party.gold 
        return true if @level != @actor.level 
        return true if $kts != nil and @time != $kts.time.to_s 
        return true if $kts == nil and @time != game_time
      end
    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 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
 

khmp

Sponsor

I imagine the cause for lag is just from the sheer amount of things being drawn. Also this window covers the whole screen. That is enormous for a window that is responsible for drawing information every 30 frames. The only way to eliminate the lag is by doing specialized checks and ONLY clearing/drawing what needs to be. You would need to do some restructuring of course but it would be little more efficient. I did something like this before:
Code:
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Define the color that will draw over something and leave nothing. Like
    # an eraser of sorts.
    clear_color = Color.new(0, 0, 0, 0)
    
    # They will dictate where to draw on the window.
    x, y = 0, 0
    
    # Draw the Hitpoints of the Party Leader.
    if @actor_hp != @actor.hp
      # Save the new value.
      @actor_hp = @actor.hp
      # Create a rectangle to clear the portion we will draw to.
      rect = Rect.new(x + 32, y, 100, 32)
      # Clear out the draw position. So text doesn't just draw over old text.
      self.contents.fill_rect(rect, clear_color)
      # Draw the health bar.
      draw_actor_hp(@actor, x + 32, y, 160)
    end
    
    # Increment our drawing position. Even if nothing is redrawn.
    y += 32
    
    # Draw the Skill Points of the Party Leader.
    if @actor_sp != @actor.sp
      # Save the new value
      @actor_sp = @actor.sp
      # Create a rectangle to clear the portion we will draw to.
      rect = Rect.new(x + 32, y, 100, 32)
      # Clear out the draw position. So text doesn't just draw over old text.
      self.contents.fill_rect(rect, clear_color)
      # Draw the health bar.
      draw_actor_sp(@actor, x + 32, y, 160)
    end
    
    # Increment our drawing position. Even if nothing is redrawn.
    y += 32
    
    # Draw the Experience of the Party Leader.
    if @actor_exp != @actor.exp
      # Save the new value.
      @actor_exp = @actor.exp
      # Create a rectangle to clear the portion we will draw to.
      rect = Rect.new(x + 32, y, 100, 32)
      # Clear out the draw position. So text doesn't just draw over old text.
      self.contents.fill_rect(rect, clear_color)
      # Draw the health bar.
      draw_actor_exp(@actor, x + 32, y)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update 
  #--------------------------------------------------------------------------
  def update
    # Every time the screen count reaches a multiple of the frame_rate
    # call refresh.
    if (Graphics.frame_count % 30) == 0
      # Save the lead actor/party leader. He will be used in comparison
      @actor = $game_party.actors[0]
      refresh
    end
  end
Now hopefully I've set up a battle plan for you gammer. But if you still need help let me know. The basic premise... Don't clear the whole thing and redraw the whole thing when one thing changes. Clear and redraw only what changes.
 
Okay, I know this might take some time for you, but do you think that you could edit my script to make it do this, and I will see what you did, so I can remember this in the future? I would really appreciate it :D

EDIT: Here is the final, it is still doing that lag thing, but it runs at 30 FPS, so, could someone, anyone help?

here is the script.
Code:
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# Shifter HUD 
# v 1.0
# Author - Joshua Long
# This HUD is made for Shifter.
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:

#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
 #*Window_hud
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
class Window_hud < Window_Base
  def initialize
    super(-10, -10, 700, 700)
    self.contents = Bitmap.new(750 - 32, 750 - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 16
    self.back_opacity = 0
    self.opacity = 0
    refresh
  end
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
  # * Game Time
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
  def game_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)
    return text
  end
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# Defines what goes into the hud
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    @oldsp = @actor ? @actor.sp : 0
    @oldmaxsp = @actor ? @actor.maxsp : 0
    @oldhp = @actor ? @actor.hp : 0
    @oldmaxhp = @actor ? @actor.maxhp : 0
    @str = @actor ? @actor.str : 0
    @agi = @actor ? @actor.agi : 0
    @int = @actor ? @actor.int : 0
    @dex = @actor ? @actor.dex : 0
    @time = game_time
    @time = $kts.time.to_s if $kts != nil
    return if !@actor
    bitmap = RPG::Cache.picture("hud")
    self.contents.blt(-5, -5, bitmap, Rect.new(0, 0, 640, 480))
    draw_bar(10, 460, @actor.sp, @actor.maxsp, 125, 10, Color.new(170, 170, 0, 255), Color.new(235, 230, 0, 255))
    draw_bar(10, 440, @actor.hp, @actor.maxhp, 125, 10, Color.new(0, 175, 0, 255), Color.new(0, 73, 0, 255))
    @oldsp != @actor.sp or @oldmaxsp != @actor.maxsp 
    @oldsp = @actor.sp 
    @oldmaxsp = @actor.maxsp 
    self.contents.draw_text(15, 445, 120, 32, "Stamina: " +$game_party.actors[0].sp.to_s + "/" +$game_party.actors[0].maxsp.to_s)
    @oldhp != @actor.hp or @maxhp != @actor.maxhp
    @oldhp = @actor.hp 
    @maxhp = @actor.maxhp
    self.contents.draw_text(15, 425, 120, 32, "Health: " +$game_party.actors[0].hp.to_s + "/" +$game_party.actors[0].maxhp.to_s)
    draw_actor_name(@actor, 585, 0)
    @str != @actor.str
    @str != @actor.str
    self.contents.draw_text(5, 20, 100, 32, "Strength: " +$game_party.actors[0].str.to_s)
    @agi != @actor.agi 
    @agi = @actor.agi 
    self.contents.draw_text(5, 34, 100, 32, "Agility: " +$game_party.actors[0].agi.to_s)
    @int != @actor.int
    @int = @actor.int
    self.contents.draw_text(5, 48, 100, 32, "Intelligence: " +$game_party.actors[0].int.to_s)
    @dex != @actor.dex
    @dex = @actor.dex
    self.contents.draw_text(5, 62, 100, 32, "Dexterity: " +$game_party.actors[0].dex.to_s)
    @gold_n != $game_party.gold 
    @gold_n = $game_party.gold 
    self.contents.draw_text(395, 13, 640, 32, $game_party.gold.to_s)
    @level != @actor.level
    @level = @actor.level
    self.contents.font.color = system_color
    self.contents.font.color = normal_color
    self.contents.font.size = 16
    self.contents.draw_text(100, 20, 640, 32, "Level:")
    self.contents.draw_text(150, 20, 640, 32, @actor.level.to_s)
    @actor != $game_party.actors[0]
    @actor = $game_party.actors[0]
    draw_actor_graphic(@actor, 600, 75)
    self.contents.draw_text(485, 13, 120, 32, @time.to_s)
    weapon = $data_weapons[$game_party.actors[0].weapon_id]
    unless weapon.nil?
    weapon_name = weapon.name
    weapon_icon = RPG::Cache.icon(weapon.icon_name)
    self.contents.blt(579, 430, weapon_icon, weapon_icon.rect)
    self.contents.draw_text(579, 405, 120, 32, weapon_name)
  end
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
  # * Update
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
def update
    super
    refresh if something_changed?
  end
end
    def something_changed?
     if Graphics.frame_count % 30 == 0
        actor = $game_party.actors[0]
        @actor = $game_party.actors[0]
        actor != @actor
        @oldhp != @actor.hp or @maxhp != @actor.maxhp
        @oldsp != @actor.sp or @oldmaxsp != @actor.maxsp  
        @str != @actor.str
        @agi != @actor.agi 
        @int != @actor.int
        @dex != @actor.dex
        @gold_n != $game_party.gold 
        @level != @actor.level 
        refresh
      end
    end
  end

#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
 #*Scene_Map
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
class Scene_Map
  
  SWITCH_ID = 1
  $center_hud = true
  
  alias hud_main main
  alias hud_update update
  
  def main
    @size = $game_party.actors.size
    hud_main
    @hud_window.dispose
    for i in 0...$game_party.actors.size
      @hud_dummy[i].dispose
    end
  end
  
  def update
    if @size != $game_party.actors.size
      @hud_window.refresh
      show_window
    end
    if @hud != true
      main_window
    end
    turn_hud_on_off
    @hud_window.update
    hud_update
  end
  
  def show_window
    @size = $game_party.actors.size
    for i in 0..3
      @hud_dummy[i].visible = ($game_party.actors[i] != nil)
    end
  end
  
  def main_window
    @opacity = 200
    @hud_dummy = []
    for i in 0...4
      y = $game_party.actors.size - 1
        x = 240 - (y * 80)
      if $center_hud == true
      @hud_dummy[i] = Window_Base.new(160 * i + x, 372,160, 108)
    else
      @hud_dummy[i] = Window_Base.new(160 * i, 372,160, 108)
      end
      @hud_dummy[i].opacity = @opacity
      @hud_dummy[i].visible = false
    end
    @hud_window = Window_hud.new
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = $game_party.actors[i] != nil
    end
    @hud = true
  end
  
def turn_hud_on_off
 if $game_switches[SWITCH_ID] == true
  @hud_window.visible = false
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = false
    end
  end
  
  
  if $game_switches[SWITCH_ID] == false
    @hud_window.visible = true
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = false
    end
  end
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 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
 
Ok. It's not exactly the same. I took the liberty of cleaning up ALOT of the code.

Code:
#==============================================================================
# ** Shifter HUD
#------------------------------------------------------------------------------
# SephirothSpawn
# Original Version by Joshua Long
# Version 2.0
# 2008-07-30
#==============================================================================

#==============================================================================
# ** Window_HUD
#==============================================================================

class Window_HUD < Window_Base
  #--------------------------------------------------------------------------
  # * Visible Switch
  #--------------------------------------------------------------------------
  Visible_Switch = 1
  Color_HP_Start = Color.new(0, 175, 0)
  Color_HP_Finish = Color.new(0, 73, 0)
  Color_SP_Start = Color.new(170, 170, 0)
  Color_SP_Finish = Color.new(235, 230, 0)
  Color_Clear = Color.new(0, 0, 0, 0)
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 640)
    begin
      self.contents = RPG::Cache.picture('HUD')
    rescue
      self.contents = Bitmap.new(width - 32, width - 32)
    end
    self.contents.font.name = 'Arial'
    self.contents.font.size = 16
    self.back_opacity = 0
    self.opacity = 0
    update
  end
  #--------------------------------------------------------------------------
  # * Game Time
  #--------------------------------------------------------------------------
  def game_time
    t = Graphics.frame_count / Graphics.frame_rate
    return sprintf("%02d:%02d:%02d", t / 60 / 60, t / 60 % 60, t % 60)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Saves Actor
    @actor = $game_party.actors[0]
    # If nil Actor
    if @actor.nil?
      self.contents.clear
      return
    end
    # Draw HP
    if @hp != @actor.hp || @maxhp != @actor.maxhp
      @hp = @actor.hp
      @maxhp = @actor.maxhp
      self.contents.fill_rect(0, 404, 128, 24, Color_Clear)
      self.contents.draw_seph_gradient_bar(0, 414, @hp, @maxhp, 128, 10, 
        Color_HP_Start, Color_HP_Finish, Color_Clear)
      self.contents.draw_text(4, 404, 120, 16, 
        "#{$data_system.words.hp}: #{@hp}/#{@maxhp}")
    end
    # Draw SP
    if @sp != @actor.sp || @maxsp != @actor.maxsp
      @sp = @actor.sp
      @maxsp = @actor.maxsp
      self.contents.fill_rect(0, 428, 128, 24, Color_Clear)
      self.contents.draw_seph_gradient_bar(0, 438, @sp, @maxsp, 128, 10, 
        Color_SP_Start, Color_SP_Finish, Color_Clear)
      self.contents.draw_text(4, 428, 120, 16, 
        "#{$data_system.words.sp}: #{@hp}/#{@maxsp}")
    end
    # Draw Name
    if @name != @actor.name
      @name = @actor.name
      self.contents.fill_rect(0, 0, 96, 16, Color_Clear)
      self.contents.draw_text(0, 0, 96, 16, @name)
    end
    # Draw Level
    if @level != @actor.level
      @level = @actor.level
      self.contents.fill_rect(0, 16, 96, 16, Color_Clear)
      self.contents.draw_text(0, 16, 96, 16, "Level: #{@level}")
    end
    # Draw STR
    if @str != @actor.str
      @str = @actor.str
      self.contents.fill_rect(0, 32, 96, 16, Color_Clear)
      self.contents.draw_text(0, 32, 96, 16, 
        "#{$data_system.words.str}: #{@str}")
    end
    # Draw DEX
    if @dex != @actor.dex
      @dex = @actor.dex
      self.contents.fill_rect(0, 48, 96, 16, Color_Clear)
      self.contents.draw_text(0, 48, 96, 16, 
        "#{$data_system.words.dex}: #{@dex}")
    end
    # Draw Int
    if @int != @actor.int
      @int = @actor.int
      self.contents.fill_rect(0, 64, 96, 16, Color_Clear)
      self.contents.draw_text(0, 64, 96, 16, 
        "#{$data_system.words.int}: #{@int}")
    end
    # Draw Agi
    if @agi != @actor.agi
      @agi = @actor.agi
      self.contents.fill_rect(0, 80, 96, 16, Color_Clear)
      self.contents.draw_text(0, 80, 96, 16, 
        "#{$data_system.words.agi}: #{@agi}")
    end
    # Draw Time
    if @time != (t = game_time)
      @time = t
      self.contents.fill_rect(510, 0, 98, 16, Color_Clear)
      self.contents.draw_text(510, 0, 96, 16, @time, 2)
    end
    # Draw Gold
    if @gold != $game_party.gold
      @gold = $game_party.gold
      self.contents.fill_rect(510, 16, 98, 16, Color_Clear)
      self.contents.draw_text(510, 16, 96, 16,
        "#{$data_system.words.gold}: #{@gold}", 2)
    end
    # Draw Weapon
    if @weapon_id != @actor.weapon_id
      @weapon_id = @actor.weapon_id
      self.contents.fill_rect(448, 424, 160, 24, Color_Clear)
      weapon = $data_weapons[@weapon_id]
      if weapon.nil?
        self.contents.draw_text(448, 432, 96, 16, 'Unarmed', 2)
      else
        icon = RPG::Cache.icon(weapon.icon_name)
        self.contents.blt(584, 424, icon, icon.rect)
        self.contents.draw_text(448, 432, 132, 16, weapon.name, 2)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Alter Visibility
    self.visible = $game_switches[Visible_Switch]
    # Refresh Window
    refresh
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_shifterhud_scnmap_main,   :main
  alias_method :seph_shifterhud_scnmap_update, :update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create HUD
    @hud_window = Window_HUD.new
    # Original Main Processing
    seph_shifterhud_scnmap_main
    # Dispose HUD
    @hud_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update HUD
    @hud_window.update
    # Original Update
    seph_shifterhud_scnmap_update
  end
end

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  #-------------------------------------------------------------------------
  # * Name      : Draw Gradient Bar
  #   Info      : Draws a Gradient Bar
  #   Author    : SephirothSpawn
  #   Call Info : Four to Nince Arguments
  #               Integer x and y Defines Position
  #               Integer min and max Defines Dimensions of Bar
  #               Start Bar Color and End Color - Colors for Gradient Bar
  #               Background Bar Color
  #-------------------------------------------------------------------------
  def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
      s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
    # Draw Border
    self.fill_rect(x, y, width, height, b_color)
    # Draws Bar
    for i in 1...((cur / max.to_f) * (width - 1))
      c = Color.color_between(s_color, e_color, (i / width.to_f))
      self.fill_rect(x + i, y + 1, 1, height - 2, c)
    end
  end
end
 
Code:
#==============================================================================
# ** Color
#==============================================================================

class Color
  #-------------------------------------------------------------------------
  # * Color Between Memory
  #-------------------------------------------------------------------------
  @color_between = {}
  #-------------------------------------------------------------------------
  # * Name      : Color Between
  #   Info      : Gets Color Between Two colors given the percent
  #   Author    : SephirothSpawn
  #   Call Info : Start Color, Finish Color, Percent
  #-------------------------------------------------------------------------
  def self.color_between(color_a, color_b, percent = 0.5)
    # Gets Save Key
    key = [color_a, color_b, percent]
    if @color_between.has_key?(key)
      return @color_between[key]
    end
    # Calculates New Color
    r = Integer(color_a.red   + (color_b.red   - color_a.red)   * percent)
    g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
    b = Integer(color_a.blue  + (color_b.blue  - color_a.blue)  * percent)
    a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
    # Saves Color
    @color_between[key] = Color.new(r, g, b, a)
    # Returns Color
    return @color_between[key]
  end
end

Add that below your code above. Please, stop PMing me. You are making me not want to help you at all.
 
I am sorry. Thanks for the help though, I won't bother you anymore.

EDIT: I know someone has to know how to do this, but every time something is updated, the number before doesn't disappear, what is wrong?

Code:
#==============================================================================
# ** Shifter HUD
#------------------------------------------------------------------------------
# SephirothSpawn
# Original Version by Joshua Long
# Version 2.0
# 2008-07-30
#==============================================================================

#==============================================================================
# ** Window_HUD
#==============================================================================

class Window_HUD < Window_Base
  #--------------------------------------------------------------------------
  # * Visible Switch
  #--------------------------------------------------------------------------
  Visible_Switch = 1
  Color_HP_Start = Color.new(0, 175, 0)
  Color_HP_Finish = Color.new(0, 73, 0)
  Color_SP_Start = Color.new(170, 170, 0)
  Color_SP_Finish = Color.new(235, 230, 0)
  Color_Clear = Color.new(0, 0, 0, 0)
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(-10, -10, 700, 700)
    begin
      self.contents = RPG::Cache.picture('HUD')
    rescue
      self.contents = Bitmap.new(width - 32, width - 32)
    end
    self.contents.font.name = 'Arial'
    self.contents.font.size = 16
    self.back_opacity = 0
    self.opacity = 0
    update
  end
  #--------------------------------------------------------------------------
  # * Game Time
  #--------------------------------------------------------------------------
  def game_time
    t = Graphics.frame_count / Graphics.frame_rate
    return sprintf("%02d:%02d:%02d", t / 60 / 60, t / 60 % 60, t % 60)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Saves Actor
    @actor = $game_party.actors[0]
    # If nil Actor
    if @actor.nil?
      self.contents.clear
      return
    end
    # Draw HP
    if @hp != @actor.hp || @maxhp != @actor.maxhp
      @hp = @actor.hp
      @maxhp = @actor.maxhp
      self.contents.draw_seph_gradient_bar(10, 440, @hp, @maxhp, 128, 10, 
        Color_HP_Start, Color_HP_Finish, Color_Clear)
      self.contents.draw_text(15, 425, 120, 32, "Health: " +$game_party.actors[0].hp.to_s + "/" +$game_party.actors[0].maxhp.to_s)
    end
    # Draw SP
    if @sp != @actor.sp || @maxsp != @actor.maxsp
      @sp = @actor.sp
      @maxsp = @actor.maxsp
      self.contents.draw_seph_gradient_bar(10, 460, @sp, @maxsp, 128, 10, 
        Color_SP_Start, Color_SP_Finish, Color_Clear)
      self.contents.draw_text(15, 445, 120, 32, "Stamina: " +$game_party.actors[0].sp.to_s + "/" +$game_party.actors[0].maxsp.to_s)
    end
    # Draw Name
    if @name != @actor.name
      @name = @actor.name
      self.contents.draw_text(585, 0, 96, 16, @name)
    end
    # Draw Level
    if @level != @actor.level
      @level = @actor.level
      self.contents.draw_text(100, 20, 96, 16, "Level: #{@level}")
    end
    # Draw STR
    if @str != @actor.str
      @str = @actor.str
      self.contents.draw_text(5, 20, 96, 16, "#{$data_system.words.str}: #{@str}")
    end
    # Draw DEX
    if @dex != @actor.dex
      @dex = @actor.dex
      self.contents.draw_text(5, 34, 96, 16, "#{$data_system.words.dex}: #{@dex}")
    end
    # Draw Int
    if @int != @actor.int
      @int = @actor.int
      self.contents.draw_text(5, 48, 96, 16, "#{$data_system.words.int}: #{@int}")
    end
    # Draw Agi
    if @agi != @actor.agi
      @agi = @actor.agi
      self.contents.draw_text(5, 62, 96, 16, "#{$data_system.words.agi}: #{@agi}")
    end
    # Draw Time
    if @time != (t = $kts.time.to_s if $kts != nil)
      @time = t
      self.contents.draw_text(485, 13, 96, 16, @time, 2)
    end
    # Draw Gold
    if @gold != $game_party.gold
      @gold = $game_party.gold
      self.contents.draw_text(395, 13, 96, 16,"#{$data_system.words.gold}: #{@gold}", 2)
    end
    # Draw Weapon
    if @weapon_id != @actor.weapon_id
      @weapon_id = @actor.weapon_id
      weapon = $data_weapons[@weapon_id]
      if weapon.nil?
        self.contents.draw_text(584, 424, 96, 16, 'Unarmed', 2)
      else
        icon = RPG::Cache.icon(weapon.icon_name)
        self.contents.blt(584, 424, icon, icon.rect)
        self.contents.draw_text(575, 409, 132, 16, weapon.name, 2)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Alter Visibility
    self.visible = $game_switches[Visible_Switch]
    # Refresh Window
    refresh
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_shifterhud_scnmap_main,   :main
  alias_method :seph_shifterhud_scnmap_update, :update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create HUD
    @hud_window = Window_HUD.new
    # Original Main Processing
    seph_shifterhud_scnmap_main
    # Dispose HUD
    @hud_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update HUD
    @hud_window.update
    # Original Update
    seph_shifterhud_scnmap_update
  end
end

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  #-------------------------------------------------------------------------
  # * Name      : Draw Gradient Bar
  #   Info      : Draws a Gradient Bar
  #   Author    : SephirothSpawn
  #   Call Info : Four to Nince Arguments
  #               Integer x and y Defines Position
  #               Integer min and max Defines Dimensions of Bar
  #               Start Bar Color and End Color - Colors for Gradient Bar
  #               Background Bar Color
  #-------------------------------------------------------------------------
  def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
      s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
    # Draw Border
    self.fill_rect(x, y, width, height, b_color)
        # Draws Bar
    for i in 1...((cur / max.to_f) * (width - 1))
      c = Color.color_between(s_color, e_color, (i / width.to_f))
      self.fill_rect(x + i, y + 1, 1, height - 2, c)
    end
  end
end
#==============================================================================
# ** Color
#==============================================================================

class Color
  #-------------------------------------------------------------------------
  # * Color Between Memory
  #-------------------------------------------------------------------------
  @color_between = {}
  #-------------------------------------------------------------------------
  # * Name      : Color Between
  #   Info      : Gets Color Between Two colors given the percent
  #   Author    : SephirothSpawn
  #   Call Info : Start Color, Finish Color, Percent
  #-------------------------------------------------------------------------
  def self.color_between(color_a, color_b, percent = 0.5)
    # Gets Save Key
    key = [color_a, color_b, percent]
    if @color_between.has_key?(key)
      return @color_between[key]
    end
    # Calculates New Color
    r = Integer(color_a.red   + (color_b.red   - color_a.red)   * percent)
    g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
    b = Integer(color_a.blue  + (color_b.blue  - color_a.blue)  * percent)
    a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
    # Saves Color
    @color_between[key] = Color.new(r, g, b, a)
    # Returns Color
    return @color_between[key]
  end
end
 
I didn't put those lines of code in there for nothing. ;)

Those lines with:
Code:
self.contents.fill_rect(x, y, width, height, Color_Clear)

That clears the areas where text is drawn, vs. clearing and drawing everything over again.

So every time you draw text, clear that area. Like I had above.
 
Create a sub-sprite in the window.
Code:
#==============================================================================
# ** Shifter HUD
#------------------------------------------------------------------------------
# SephirothSpawn
# Original Version by Joshua Long
# Version 2.0
# 2008-07-30
#==============================================================================

#==============================================================================
# ** Window_HUD
#==============================================================================

class Window_HUD < Window_Base
  #--------------------------------------------------------------------------
  # * Visible Switch
  #--------------------------------------------------------------------------
  Visible_Switch = 1
  Color_HP_Start = Color.new(0, 175, 0)
  Color_HP_Finish = Color.new(0, 73, 0)
  Color_SP_Start = Color.new(170, 170, 0)
  Color_SP_Finish = Color.new(235, 230, 0)
  Color_Clear = Color.new(0, 0, 0, 0)
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(-10, -10, 700, 700)
    self.contents = Bitmap.new(width - 32, width - 32)
    self.contents.font.name = 'Arial'
    self.contents.font.size = 16
    self.back_opacity = 0
    self.opacity = 0
    @sprite = Sprite.new
    @sprite.z = self.z - 1
    @sprite.bitmap = RPG::Cache.picture('HUD')
    @sprite.x = self.x
    @sprite.y = self.y
    update
  end
  #--------------------------------------------------------------------------
  # * Game Time
  #--------------------------------------------------------------------------
  def game_time
    t = Graphics.frame_count / Graphics.frame_rate
    return sprintf("%02d:%02d:%02d", t / 60 / 60, t / 60 % 60, t % 60)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Saves Actor
    @actor = $game_party.actors[0]
    # If nil Actor
    if @actor.nil?
      self.contents.clear
      return
    end
    # Draw HP
    if @hp != @actor.hp || @maxhp != @actor.maxhp
      @hp = @actor.hp
      @maxhp = @actor.maxhp
      self.contents.draw_seph_gradient_bar(10, 440, @hp, @maxhp, 128, 10, 
        Color_HP_Start, Color_HP_Finish, Color_Clear)
      self.contents.draw_text(15, 425, 120, 32, "Health: " +$game_party.actors[0].hp.to_s + "/" +$game_party.actors[0].maxhp.to_s)
    end
    # Draw SP
    if @sp != @actor.sp || @maxsp != @actor.maxsp
      @sp = @actor.sp
      @maxsp = @actor.maxsp
      self.contents.draw_seph_gradient_bar(10, 460, @sp, @maxsp, 128, 10, 
        Color_SP_Start, Color_SP_Finish, Color_Clear)
      self.contents.draw_text(15, 445, 120, 32, "Stamina: " +$game_party.actors[0].sp.to_s + "/" +$game_party.actors[0].maxsp.to_s)
    end
    # Draw Name
    if @name != @actor.name
      @name = @actor.name
      self.contents.draw_text(585, 0, 96, 16, @name)
    end
    # Draw Level
    if @level != @actor.level
      @level = @actor.level
      self.contents.draw_text(100, 20, 96, 16, "Level: #{@level}")
    end
    # Draw STR
    if @str != @actor.str
      @str = @actor.str
      self.contents.draw_text(5, 20, 96, 16, "#{$data_system.words.str}: #{@str}")
    end
    # Draw DEX
    if @dex != @actor.dex
      @dex = @actor.dex
      self.contents.draw_text(5, 34, 96, 16, "#{$data_system.words.dex}: #{@dex}")
    end
    # Draw Int
    if @int != @actor.int
      @int = @actor.int
      self.contents.draw_text(5, 48, 96, 16, "#{$data_system.words.int}: #{@int}")
    end
    # Draw Agi
    if @agi != @actor.agi
      @agi = @actor.agi
      self.contents.draw_text(5, 62, 96, 16, "#{$data_system.words.agi}: #{@agi}")
    end
    # Draw Time
    if @time != (t = $kts.time.to_s if $kts != nil)
      @time = t
      self.contents.draw_text(485, 13, 96, 16, @time, 2)
    end
    # Draw Gold
    if @gold != $game_party.gold
      @gold = $game_party.gold
      self.contents.draw_text(395, 13, 96, 16,"#{$data_system.words.gold}: #{@gold}", 2)
    end
    # Draw Weapon
    if @weapon_id != @actor.weapon_id
      @weapon_id = @actor.weapon_id
      weapon = $data_weapons[@weapon_id]
      if weapon.nil?
        self.contents.draw_text(584, 424, 96, 16, 'Unarmed', 2)
      else
        icon = RPG::Cache.icon(weapon.icon_name)
        self.contents.blt(584, 424, icon, icon.rect)
        self.contents.draw_text(575, 409, 132, 16, weapon.name, 2)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    @sprite.update
    # Alter Visibility
    self.visible = $game_switches[Visible_Switch]
    # Refresh Window
    refresh
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super
    @sprite.dispose
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_shifterhud_scnmap_main,   :main
  alias_method :seph_shifterhud_scnmap_update, :update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Create HUD
    @hud_window = Window_HUD.new
    # Original Main Processing
    seph_shifterhud_scnmap_main
    # Dispose HUD
    @hud_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update HUD
    @hud_window.update
    # Original Update
    seph_shifterhud_scnmap_update
  end
end

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  #-------------------------------------------------------------------------
  # * Name      : Draw Gradient Bar
  #   Info      : Draws a Gradient Bar
  #   Author    : SephirothSpawn
  #   Call Info : Four to Nince Arguments
  #               Integer x and y Defines Position
  #               Integer min and max Defines Dimensions of Bar
  #               Start Bar Color and End Color - Colors for Gradient Bar
  #               Background Bar Color
  #-------------------------------------------------------------------------
  def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
      s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
    # Draw Border
    self.fill_rect(x, y, width, height, b_color)
        # Draws Bar
    for i in 1...((cur / max.to_f) * (width - 1))
      c = Color.color_between(s_color, e_color, (i / width.to_f))
      self.fill_rect(x + i, y + 1, 1, height - 2, c)
    end
  end
end
#==============================================================================
# ** Color
#==============================================================================

class Color
  #-------------------------------------------------------------------------
  # * Color Between Memory
  #-------------------------------------------------------------------------
  @color_between = {}
  #-------------------------------------------------------------------------
  # * Name      : Color Between
  #   Info      : Gets Color Between Two colors given the percent
  #   Author    : SephirothSpawn
  #   Call Info : Start Color, Finish Color, Percent
  #-------------------------------------------------------------------------
  def self.color_between(color_a, color_b, percent = 0.5)
    # Gets Save Key
    key = [color_a, color_b, percent]
    if @color_between.has_key?(key)
      return @color_between[key]
    end
    # Calculates New Color
    r = Integer(color_a.red   + (color_b.red   - color_a.red)   * percent)
    g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
    b = Integer(color_a.blue  + (color_b.blue  - color_a.blue)  * percent)
    a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
    # Saves Color
    @color_between[key] = Color.new(r, g, b, a)
    # Returns Color
    return @color_between[key]
  end
end
 
 

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