This is a tutorial to help people learn how to script a basic HUD.
If you want to make a good HUD, you are going to need some basic knowledge of RGSS, but not much.
There are two parts to this tutorial: The Window, and the Scene. Absolutly no screenshots will be taken; I trust you to know if it looks right, or not.
First of all, Hit F11 on your keyboard. Scroll down and highlight Main, then press Insert. This creates a new script holder for us to use.
In order to have a HUD, you will need a Bitmap, which is in a Window, or a Sprite. I think people find Windows easier, so that's what we will use.
To create a window, we type in two lines:
Code:
class Window_YourHUD < Window_Base
end
Currently, our window isn't quite a window. To fix this, will will make the initialize method.
Code:
class Window_YourHUD < Window_Base
def initialize
end
end
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
end
Now, we will create the refresh method. This is the method that draws all the text, and junk.
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
end
end
Next, we will add a method I like to do to keep it all organized, the reset_variables method.
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
reset_variables
end
def reset_variables
end
end
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
reset_variables
end
def reset_variables
@actor = $game_party.actors[0]
@old_hp = @actor ? @actor.hp : 0
@old_maxhp = @actor ? @actor.maxhp : 0
@old_sp = @actor ? @actor.sp : 0
@old_maxsp = @actor ? @actor.maxsp : 0
end
end
Now that that's settled, we will finish the refresh method.
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
reset_variables
return if !@actor
draw_actor_hp(actor, x, y)
draw_actor_sp(actor, x, y)
end
def reset_variables
@actor = $game_party.actors[0]
@old_hp = @actor ? @actor.hp : 0
@old_maxhp = @actor ? @actor.maxhp : 0
@old_sp = @actor ? @actor.sp : 0
@old_maxsp = @actor ? @actor.maxsp : 0
end
end
Finally, we will make the window refresh if necessary. We will do this in the update method.
Code:
class Window_YourHUD < Window_Base
def initialize
super(x, y, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
reset_variables
return if !@actor
draw_actor_hp(actor, x, y)
draw_actor_sp(actor, x, y)
end
def reset_variables
@actor = $game_party.actors[0]
@old_hp = @actor ? @actor.hp : 0
@old_maxhp = @actor ? @actor.maxhp : 0
@old_sp = @actor ? @actor.sp : 0
@old_maxsp = @actor ? @actor.maxsp : 0
end
def update
super
refresh if (@actor = $game_party.actors[0] or
@old_hp = @actor ? @actor.hp : 0 or
@old_maxhp = @actor ? @actor.maxhp : 0 or
@old_sp = @actor ? @actor.sp : 0 or
@old_maxsp = @actor ? @actor.maxsp : 0)
end
end
Code:
class Scene_Map
alias yourhud_main main
alias yourhud_update update
end
Code:
class Scene_Map
alias yourhud_main main
alias yourhud_update update
def main
@yourhud = Window_YourHUD.new
yourhud_main
@yourhud.dispose
end
def update
@yourhud.update
yourhud_update
end
end
That's the end of my tutorial, so save and test play your window. If you got an error, go back and try this tutorial again. I don't know why you would get an error; it's so easy to make HUDs.
Later, until next time. Yeyinde, the Local Yautja
Later, until next time. Yeyinde, the Local Yautja