HUD (Heads-Up-Display) are systems found in many games and there are several scripts that emulate this for RMXP/VX. So lets take a look at one.
Here is a quick HUD system I made for the purposes of this tutorial.
#==============================================================================
# ** Window_BasicHUD (By SephirothSpawn)
#------------------------------------------------------------------------------
# A Simple HUD System shows a HUD on the map, that shows the current actor's
# HP and SP.
#==============================================================================
#==============================================================================
# ** Window_BasicHUD
#==============================================================================
class Window_BasicHUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 224, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
update
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_hp(@actor, 0, 0, 192)
draw_actor_sp(@actor, 0, 32, 192)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @actor != $game_party.actors[0] || @hp != $game_party.actors[0].hp ||
@sp != $game_party.actors[0].sp
@actor = $game_party.actors[0]
@hp = @actor.hp
@sp = @actor.sp
refresh
end
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_basichud_scnmap_main, :main
alias_method :seph_basichud_scnmap_updt, :update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Create HUD
@hud_window = Window_BasicHUD.new
# Original Main
seph_basichud_scnmap_main
# Dispose HUD
@hud_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update HUD
@hud_window.update
# Original Update
seph_basichud_scnmap_updt
end
end
Now, this HUD creates a window on the map showing the main actor's hp and sp. But as of now, it always shows. What if we wanted to disable it if a switch is on. All we have to do is update its visibility if a switch is on. Doesn't get any simpler. Let's create a constant that lets you choose which switch that must be on for it to be visible.
#==============================================================================
# ** Window_BasicHUD
#==============================================================================
class Window_BasicHUD < Window_Base
#--------------------------------------------------------------------------
# * Visible Switch
#--------------------------------------------------------------------------
Visible_Switch = 1
Now, down in this windows update method, we'll add a single line, and presto.
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.visible = $game_switches[Visible_Switch]
Our final product:
#==============================================================================
# ** Window_BasicHUD (By SephirothSpawn)
#------------------------------------------------------------------------------
# A Simple HUD System shows a HUD on the map, that shows the current actor's
# HP and SP.
#==============================================================================
#==============================================================================
# ** Window_BasicHUD
#==============================================================================
class Window_BasicHUD < Window_Base
#--------------------------------------------------------------------------
# * Visible Switch
#--------------------------------------------------------------------------
Visible_Switch = 1
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 224, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
update
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_hp(@actor, 0, 0, 192)
draw_actor_sp(@actor, 0, 32, 192)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.visible = $game_switches[Visible_Switch]
if @actor != $game_party.actors[0] || @hp != $game_party.actors[0].hp ||
@sp != $game_party.actors[0].sp
@actor = $game_party.actors[0]
@hp = @actor.hp
@sp = @actor.sp
refresh
end
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_basichud_scnmap_main, :main
alias_method :seph_basichud_scnmap_updt, :update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Create HUD
@hud_window = Window_BasicHUD.new
# Original Main
seph_basichud_scnmap_main
# Dispose HUD
@hud_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update HUD
@hud_window.update
# Original Update
seph_basichud_scnmap_updt
end
end
Simple enough. The same can be done for most HUDs, Sprite Objects, etc. Anything that has a visible method can be toggled with this.