I've made a few tweaks which should help:
CODE
class Window_HUD < Window_Base
def initialize
super(0,0, 110, 96)
self.contents = Bitmap.new(width - 32, height - 32)
# This will make sure tis isn't visible all the time. (It should only be
# Viewed when in a battle
self.visible = false
#Make the windonw semi-transparent (In battle it won't be, but at least
#I know what method to use when needing to change the opacity
self.opacity = 225
# Get the leading actor in the party
@actor = $game_party.members[0]
# If there wasn't any actors in the party, set the HP & MP to 0
if @actor == nil
@hp = @mp = 0
# If there was an actor in the party
else
#Get hp of that actor
@hp = @actor.hp
#Get mp of the actor
@mp = @actor.mp
end
# Redraw the graphics
refresh
end
#remember to clear the contents of the window (basically, define refresh)
def refresh
self.contents.clear
# This isn't necessary, BUT, you can draw the HP icon.
bitmap = Cache.load_bitmap("Graphics/Icon/", "HP")
self.contents.blt(0,4, bitmap, Rect.new(0,0,24,24),255)
#draw the actual HP of the actor (I want a gauge here soon)
self.contents.draw_text(0, 32, 96, 32, @hp.to_s)
#draw the icon for mp on the window (255 is the opacity!)
bitmap = Cache.load_bitmap("Graphics/Icon/", "MP")
self.contents.blt(0,36, bitmap, Rect.new(0,0,24,24),255)
#draw the MP of the actor
self.contents.draw_text(32, 32, 96, 32, @mp.to_s)
end
#run each and every frame
def update
# The HUD will be visible only if this switch is on.
self.visible = $game_switches[1]
#Don't update if we can't see the window
if !self.visible
return
end
#only reresh if something has changed <-- IMPORTANT
if (@hp != @actor.hp) or (@mp != @actor.hp) or
(@actor != $game_party.members[0])
# current leading actor in the party
@actor = $game_party.members[0]
# If there wasn't any actors in the party, set the HP & MP to 0
if @actor == nil
@hp = @mp = 0
# If there was an actor in the party
else
# Get hp of that actor
@hp = @actor.hp
# Get mp of the actor
@mp = @actor.mp
end
# Redraw the graphics
refresh
end
#this allows the parent windows to do what needs to be done. (i.e
#window base and whatnot)
super
end
end
I've edited the code to get the leading actor in the party, as opposed to only getting the first actor in the database, ad I've included some checks if there isn't an actor in the party.
And in your update method, I have changed the refresh requirements to check if the hp/mp has changed for the actor (@actor.hp, not @actor_hp), as well as checking if the actor has changed.
I think that's about it, hope that helps