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.

Basic HUD Tutorial

Status
Not open for further replies.

Kahn

Member

What does make the variable super, is it a variable which is already defined or can i make in every Scene everytime a new variable caled the same?
 
The easiest way I know to do this is, first do you have HP/Max HP and SP/MaxSP defined.

So...
Code:
#Show HP in Numericals
self.contents.draw_text(x, y, 640, 32, "HP")
self.contents.draw_text(x+10, y, 640, 32, $actor_hp.to_s)
self.contents.draw_text(x+13, y, 640, 32, "/")
self.contents.draw_text(x+16, y, 640, 32, $actor_maxhp.to_s)
#Show SP in Numericals
self.contents.draw_text(x, y, 640, 32, "SP")
self.contents.draw_text(x+10, y+10, 640, 32, $actor_sp.to_s)
self.contents.draw_text(x+13, y+10, 640, 32, "/")
self.contents.draw_text(x+16, y+10, 640, 32, $actor_maxsp.to_s)

Replace the X and Y values with something of your choice, then addition part should be simple enough, just add that value onto your x or y value.

I'll try to give a better representation when I get home later, hard to do trial and error at school.
 
Hello, I've tried this various ways. I've tried the exact one in the original post. I've tried the 'initialize' update, and I've tried removing @yourhud.dispose

I still get

Script 'HUD' line 3: RGSSError occoured.

disposed window


What else should I be lookin out for? I'm not great with scripting, what can be up with line 3?
 
Let's say I wanted to make the appearance of the HUD conditional... I've tried adding an IF statement in the Scene_Map class like this:

Code:
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    if $battle
      @yourhud = Window_YourHUD.new
      yourhud_main
      @yourhud.dispose
    else
      yourhud_main
    end
  end
  def update
    if $battle
      @yourhud.update
      yourhud_update
    else
      yourhud_update
    end
  end
end

where $battle is a created global variable that I control with event scripting (Boolean). The code works fine if I comment out the IF statement itself (and the else code) but as soon as I throw the code into this conditional, It tries to tell me that @yourhud.update doesn't exist. (the code for Window_YourHUD is unmodified)

What's the deal with that?
 

Jason

Awesome Bro

Ok I need help with this, I've got it exactly the same as the Tutorial, but with my own x+y co-ordinates.

But whenever I come to test it, I get this error:

????? 'Window_YourHUD' ? 4 ??? NameError ????????
uninitialized constant Window_YourHUD::Bitamp

Can someone tell me what it means and how to fix it please, Because everytime I've tried a tutorial, I get the very same error.
 
foftime, just put @your_hud.visible = $battle right after @your_hud.update and @your_hud = Window_YourHUD.new. No need for conditionals.

jbrist, It's Bitmap, not Bitamp.
 
Followed every direction and it turned out perfectly, although I'm considering changing the draw_actor_hp to two lines:

self.contents.draw_text(x, y, width, height, "HP: ")
self.contents.draw_Text(x, y, width, height, $game_party.actors[0].hp.to_s + "/" + $game_party.actors[0].maxhp.to_s)
...
etc.

the x, y, width, height, you just plug it wherever you wish.

I added Sephiroth's "Bars". This way you can adjust where you display "HP", and the actual HP further apart if you wish -- since the default method only lets you have so much space inbetween the two. The only type of bars I can do is the beginner ones for now.

To Illustrate the differences:

HUD Window with Draw_actor
HUD Window with self.contents.draw_text...
 

Eadwyn

Member

Great tutorial. Now if I only understood Ruby..... Oh well, there is a time to learn for everything. Thanks anyway, this tutorial should come in handy for the future.
 

xiffix

Member

Hi, I was triying to make a HUD but I get some errors..
this is my script:

Code:
class Scene_Map
  alias Window_Status_main main
  alias Window_Status_update update
  def main
    #When I try @Window_Status = Window_Window_Status.new in the next line it doesn't
    #work either.
    @Window_Status = Window_Status.new
    Window_Status_main
    @Window_Status.dispose
  end
  def update
    @Window_Status.update
    Window_Status_update
  end
end

and the window:

Code:
class Window_Status < Window_Base
  
  def initialize(actor)
    super(0, 0, 320, 240)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = $fontsize
    self.back_opacity = 145
    @actor = actor
    refresh
  end

  def refresh
    self.contents.clear
    draw_actor_graphic(@actor, 40, 80)
    draw_actor_name(@actor, 4, 0)


    draw_actor_parameter(@actor, 4, 20, 0)
    draw_actor_parameter(@actor, 4, 40, 1)
    draw_actor_parameter(@actor, 4, 60, 2)
    draw_actor_parameter(@actor, 4, 80, 3)
    draw_actor_parameter(@actor, 4, 100, 4)
    draw_actor_parameter(@actor, 4, 120, 5)
    draw_actor_parameter(@actor, 4, 140, 6)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 48, 80, 32, "")
    self.contents.draw_text(320, 80, 80, 32, "")
    self.contents.font.color = normal_color
  end
 
end

When I go to this Window by the Menu (the ESCAPE menu*) It works.

Can someone tell me what I'm doing wrong?
 
DeadCaL;136009 said:
Hello, I've tried this various ways. I've tried the exact one in the original post. I've tried the 'initialize' update, and I've tried removing @yourhud.dispose

I still get

Script 'HUD' line 3: RGSSError occoured.

disposed window


What else should I be lookin out for? I'm not great with scripting, what can be up with line 3?
it might be a bit old but change:
Code:
@yourhud.dispose
to
Code:
@yourhud.dispose if !@yourhud.disposed?
to fix the disposed window error
 
Can you help me with my hud..?

I'm trying to make it so my hero's sprite is displayed next to his hp/sp, but I have no clue how. Also if you can, explain to me how I replace my window with a picture...

Code:
class Window_YourHUD < Window_Base
  def initialize
    super(0, 0, 350, 60)
 self.contents = Bitmap.new(width - 32, height - 32)
 self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 2, 2)
    draw_actor_sp(@actor, 170,2)
  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
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
 
@_@ i could alittle help, this my 3rd day of working with Rpg maker xp. i been trying to make a window base of hud system that well show the level of a set skill like fishing. problem is when the skill goes the hud does not update. stays at 0, And yes i read all the "basic hub" example tutorial and i do see the "update" part but dont understand it nor how to make it with variables and not actors.

ill show you what i have so far:

class Window_YourHUD < Window_Base
#----------------------------------------------------------------------
# * Object Initialization
#----------------------------------------------------------------------
def initialize
super(0, 416, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh # Calls the refresh function in this class
end

def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.font.size = 20
self.contents.draw_text(65, 5, 100, 32, $game_variables[1].to_s)
self.contents.draw_text(5, 5, 100, 32, "Fishing" )
end

end

class Scene_Map
alias yourhud_main main
def main
@yourhud = Window_YourHUD.new
refresh
@refresh.dispose
end
end
 
Just set an instance variable to the game variable on a refresh, and check that instance variable to the main one each update. Something like this:
Code:
class Fishing_HUD < Window_Base
  def initialize
    super(0, 416, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = 20
    refresh
  end
  def refresh
    self.contents.clear
    @fishing_var = $game_variables[1]
    self.contents.draw_text(65, 5, 100, 32, @fishing_var.to_s)
    self.contents.draw_text(5, 5, 100, 32, 'Fishing')
  end
  def update
    super
    refresh if @fishing_var != $game_variables[1]
  end
end
class Scene_Map
  alias fishing_hud_main main
  alias finishg_hud_update
  def main
    @fishing_hud = Fishing_HUD.new
    fishing_hud_main
    @fishing_hud.dispose
  end
  def update
    @fishing_hud.update
    fishing_hud_update
  end
end
 
thanks alot,but theres some kind of problem on line 22? and iam noob and need help
line 22 is def main in the class Scene_Map
i tryed playing around to cross search over hud systems, i have no clue why this aint working
 
Swordhunter, there is no finished HUD. This is a tutorial on HOW to make a basic one.
Bagginhard, sorry about the small error. A little mistake on my part. Replace this line:
Code:
alias finishg_hud_update
With this:
Code:
alias finishg_hud_update update
 
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