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.

HUD help

OK, I need some help with adding a weapon cycle to a HUD I've edited, and a bit of help on displaying the actual HUD. I've got the HUD mainly sorted, but here's what I've got for the weapon cycle:

Code:
    # If Q button was pressed

    if Input.trigger?(Input::L)

      # If event is running, or menu is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.menu_disabled

 

Then after that I need some help with the code. What's the code for changing the main player' equiped weapon?

Then the actual HUD. At the moment, I have the code for the hud_sprite at all the right points in Spriteset Map (i.e. @hud_sprite.dispose, @hud_sprite.update) but the HUD (which is for my evented ABS) doesn't update the health bar unless you go in and out of the menu. In other words, until Scene_Map updates. How can I make the HUD update constantly?

Well, theres my two questions, hope someone can help. Thanks in advance.
 
Every window must be updated inside a scene, and rmxp changes the scene: scene menu, scene battle, etc. You can add @hud_sprite.update in every scene that affects the HUD, but you'll have to make it a global variable, ie: $game_map.yourHUD.

Anyway, why is your HUD visible during scene_menu?
You can create hide_HUD/show_HUD methods. It'll be handy for battles/ cut scenes where the HUD may be in the way, and it's another way to solve this.
Hide the HUD in scene_menu, and show it when exiting the menu, after the dispose lines. Only call show_HUD if the HUD wasn't hidden when the menu started:
show/hide HUD should look like this:
[rgss]class MY_HUD
attr_reader :hidden
def initialize
@hidden = false
#...
end
 
def update
 self.contents.clear
 return if @hidden
# draw the HUD here
end
 
def hide
@hidden = true
end
 
def show
@hidden = false
end
 
end
[/rgss]
Inside scene_Menu's main, do:
[rgss]hud_was_hidden = $game_map.yourHUD.hidden
$game_map.yourHUD.hide
#...(scene menu's loop)
$game_map.yourHUD.show unless hud_was_hidden
 
[/rgss]
 
Thanks, but... sorry? Maybe I wasn't clear enough. I have the HUD updating in Spriteset_Map, and that's all you need isn't it? I don't want the HUD visible in the menu, and it's not, what I want is the health bar updating. Heres the script I've edited:

Code:
class Sprite_HUD < Sprite

  def initialize

    super

    self.bitmap = RPG::Cache.picture("LMS HUD")

    self.z = 1000

    self.x = 640-self.bitmap.width

    self.y = 480-self.bitmap.height

    @current_hp = $game_party.actors[0].hp

    @current_mp = $game_party.actors[0].sp

    @current_ammo = $game_variables[1]

    @current_weapon = $game_party.actors[0].weapon_id

    refresh

  end

  def refresh

    self.bitmap.clear

    self.bitmap.dispose

    self.bitmap = RPG::Cache.picture("LMS HUD")

    self.bitmap.font.name = 'Lucida Console'

    self.bitmap.font.size = 18

    x = 19; y = 21; width = 103; height = 10;

    percentage = @current_hp / $game_party.actors[0].maxhp.to_f

    barwidth = width * percentage

    self.bitmap.fill_rect(x, y, width-barwidth, height, Color.new(0, 0, 0))

    x = 19; y = 41; width = 103; height = 10;

    percentage = @current_mp / $game_party.actors[0].maxsp.to_f

    barwidth = width * percentage

    self.bitmap.fill_rect(x, y, width-barwidth, height, Color.new(0, 0, 0))

    image = RPG::Cache.icon($data_weapons[@current_weapon].icon_name)

    self.bitmap.blt(120, -15, image, Rect.new(0, 0, 96, 96))

    self.bitmap.draw_text(125, 38, 58, 32, @current_ammo.to_s, 1)

    self.bitmap.draw_text(145, 38, 58, 32, "/", 1)

    self.bitmap.draw_text(165, 38, 58, 32, "12", 1)

  end

  def update

    if @current_hp != $game_party.actors[0].hp or @current_mp != $game_party.actors[0].sp or

          @current_ammo != $game_variables[1] or @current_weapon != $game_party.actors[0].weapon_id

      @current_hp = $game_party.actors[0].hp

      @current_mp = $game_party.actors[0].sp

      @current_ammo = $game_variables[1]

      @current_weapon = $game_party.actors[0].weapon_id

      refresh

    end

  end

end

 

 

And here's what I have Spriteset_Map like:

Code:
#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @tilemap = Tilemap.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data

    @tilemap.priorities = $game_map.priorities

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @character_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites.push(sprite)

    end

    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    @hud_sprite = Sprite_HUD.new

    # Frame update

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    # Dispose of tilemap

    @tilemap.tileset.dispose

    for i in 0..6

      @tilemap.autotiles[i].dispose

    end

    @tilemap.dispose

    # Dispose of panorama plane

    @panorama.dispose

    # Dispose of fog plane

    @fog.dispose

    # Dispose of character sprites

    for sprite in @character_sprites

      sprite.dispose

    end

    # Dispose of weather

    @weather.dispose

    # Dispose of picture sprites

    for sprite in @picture_sprites

      sprite.dispose

    end

    # Dispose of timer sprite

    @timer_sprite.dispose

    @hud_sprite.dispose

    # Dispose of viewports

    @viewport1.dispose

    @viewport2.dispose

    @viewport3.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If panorama is different from current one

    if @panorama_name != $game_map.panorama_name or

       @panorama_hue != $game_map.panorama_hue

      @panorama_name = $game_map.panorama_name

      @panorama_hue = $game_map.panorama_hue

      if @panorama.bitmap != nil

        @panorama.bitmap.dispose

        @panorama.bitmap = nil

      end

      if @panorama_name != ""

        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)

      end

      Graphics.frame_reset

    end

    # If fog is different than current fog

    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue

      @fog_name = $game_map.fog_name

      @fog_hue = $game_map.fog_hue

      if @fog.bitmap != nil

        @fog.bitmap.dispose

        @fog.bitmap = nil

      end

      if @fog_name != ""

        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)

      end

      Graphics.frame_reset

    end

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @fog.zoom_x = $game_map.fog_zoom / 100.0

    @fog.zoom_y = $game_map.fog_zoom / 100.0

    @fog.opacity = $game_map.fog_opacity

    @fog.blend_type = $game_map.fog_blend_type

    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox

    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy

    @fog.tone = $game_map.fog_tone

    # Update character sprites

    for sprite in @character_sprites

      sprite.update

    end

    # Update weather graphic

    @weather.type = $game_screen.weather_type

    @weather.max = $game_screen.weather_max

    @weather.ox = $game_map.display_x / 4

    @weather.oy = $game_map.display_y / 4

    @weather.update

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    @hud_sprite.update

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

 

Now, this works, but it doesn't update when you loose health until Spriteset_Map refreshes. As for what you've said about turning the script on and off, where would that go?
 
Sorry, I thought you said it doesn't update until you close the menu, which isn't a problem unless your HUD is visible on the menu. :p

I tested your script, and.. it works perfectly??
When you lose HP/SP on the map, refresh is called and the 2 black bars get bigger.(The hp/sp bars are part of the hud pic, I guess?) Anyway, I tested it in a new project, so the problem may be an other script/ the evented ABS.
 
Ah, really? Oh yeah, never thought it could be something conflicting... Well, it was one of my antilag scripts, which I've now deleted, and it works fine now. Thanks anyway. Can anyone answer my second question please?
 

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