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.

Refresh when HP/SP changes

I have a window,

Code:
class Window_HudBars < Window_Base
  #----------------------------------------
  # Object Initialization
  #----------------------------------------
  def initialize
    super(178, 360, 360, 60)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 200
    self.opacity = 0
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.font.size = 16
    @minhp = $game_party.actors[0].hp
    @maxhp = $game_party.actors[0].maxhp
    @minsp = $game_party.actors[0].sp
    @maxsp = $game_party.actors[0].maxsp
    draw_slant_bar(0, 0, @minhp, @maxhp, width = 144, height = 14, bar_color = Color.new(128, 0, 0, 255), end_color = Color.new(173, 14, 5, 255))
    draw_slant_bar(144, 0, @minsp, @maxsp, width = 144, height = 14, bar_color = Color.new(0, 0, 128, 255), end_color = Color.new(5, 49, 165, 255))
  end
end

I have this on the map in my Hud. I want to make it refresh if the HP or SP of the player changes. Otherwise, the bars will be wrong unless the menu is opened/closed, or unless I change maps.

Is there something I must add to Scene_Map, or to this script, or anything?
 
Replace it with this one:
Code:
class Window_HudBars < Window_Base
  #----------------------------------------
  # Object Initialization
  #----------------------------------------
  def initialize
    super(178, 360, 360, 60)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 200
    self.opacity = 0
    @old_hp = $game_party.actors[0].hp
    @old_sp = $game_party.actors[0].sp
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.font.size = 16
    @minhp = $game_party.actors[0].hp
    @maxhp = $game_party.actors[0].maxhp
    @minsp = $game_party.actors[0].sp
    @maxsp = $game_party.actors[0].maxsp
    draw_slant_bar(0, 0, @minhp, @maxhp, width = 144, height = 14, bar_color = Color.new(128, 0, 0, 255), end_color = Color.new(173, 14, 5, 255))
    draw_slant_bar(144, 0, @minsp, @maxsp, width = 144, height = 14, bar_color = Color.new(0, 0, 128, 255), end_color = Color.new(5, 49, 165, 255))
  end


def update
  super
  if @old_hp != $game_party.actors[0].hp or @old_sp != $game_party.actors[0].sp
    refresh
    @old_hp = $game_party.actors[0].hp
    @old_sp = $game_party.actors[0].sp
  end
end

You only need to update the window.
 

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