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.

Reducing lag in a Hud

Status
Not open for further replies.
I have this Hud, but it's lagging because of it constantly refreshing. Can anyone help me reduce the lag? Before I had a Hud, and got rid of most of the lag by having it only refresh if the player's HP/MP/EXP had changed. But as this has bars for all of the party's HP, as well as the HP/MP/EXP of the main character, I'm not sure how I'd go about doing that. A also plan on having the player's HP/MP rise as he walks, so I'm not sure if that's going to work to remove lag.

Code:
#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
#  This window displays the HUD
#==============================================================================

class Window_HUD < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(363-16, 232-16-2, 103+32, 75+32)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = 12
    self.contents.font.color = Color.new(0, 0, 0)
    self.z = 9999
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      x = 0 + 34
      y = i * 14 + 8
      self.contents.draw_hp_picture(x, y, actor.hp, actor.maxhp)
      self.contents.draw_text(x + 1, y, width, 12, actor.name)
    end
    now = $game_party.actors[0].now_exp
    nex = $game_party.actors[0].next_exp
    hp = $game_party.actors[0].hp
    hpm = $game_party.actors[0].maxhp
    mp = $game_party.actors[0].sp
    mpm = $game_party.actors[0].maxsp
    self.contents.draw_hp_picture_vertical(0, 2, hp, hpm, 'playerback', 'playerhp')
    self.contents.draw_hp_picture_vertical(9, 2, mp, mpm, 'playerback', 'playermp')
    self.contents.draw_hp_picture_vertical(18, 2, now, nex, 'playerback', 'playerxp')
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    refresh
  end
end
 
Code:
#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
#  This window displays the HUD
#==============================================================================

class Window_HUD < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(363-16, 232-16-2, 103+32, 75+32)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = 12
    self.contents.font.color = Color.new(0, 0, 0)
    self.z = 9999
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      x = 0 + 34
      y = i * 14 + 8
      self.contents.draw_hp_picture(x, y, actor.hp, actor.maxhp)
      self.contents.draw_text(x + 1, y, width, 12, actor.name)
    end
    @now = $game_party.actors[0].now_exp
    @nex = $game_party.actors[0].next_exp
    @hp = $game_party.actors[0].hp
    @hpm = $game_party.actors[0].maxhp
    @mp = $game_party.actors[0].sp
    @mpm = $game_party.actors[0].maxsp
    self.contents.draw_hp_picture_vertical(0, 2, @hp, @hpm, 'playerback', 'playerhp')
    self.contents.draw_hp_picture_vertical(9, 2, @mp, @mpm, 'playerback', 'playermp')
    self.contents.draw_hp_picture_vertical(18, 2, @now, @nex, 'playerback', 'playerxp')
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    actor = $game_party.actors[0]
    if (@now != actor.now_exp || @nex != actor.next_exp || @hp != actor.hp || 
        @hpm != actor.maxhp || @mp != actor.sp || @mpm != actor.maxsp)
      refresh
    end
  end
end
 
This topic has been resolved. If Wyatt or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

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