Help - Search - Members - Calendar
Full Version: Picture Layers
RPG RPG Revolution Forums > Scripting > Script Development and Support
Titanhex
Alright so I have a HUD from Vampyr SBABS. Now, I wanted to implement a stationary picture, and I have.

Problem is, the stationary picture shows up on a higher layer than the HUD, so when you come across this stationary picture on the map, it hides the HUD behind it. This of course looks bad.

So, I wanted to make the HUD picture show up above the Show Picture events.

If it helps, here is the HUD code for Vampyr Telam Ludus.

HUD
CODE
#==============================================================================
# Vampyr HUD
#==============================================================================
# Switch ID that show or hide the HUD
OnOff_Switch = 104

# Text displayed on skills window
Show_Skills = true
Skills_Text = "Abilities"

# Text displayed on items window
Show_Items = true
Items_Text = "Items"

# Text displayed on ammunitions window
Show_Ammos = true
Ammo_Text = "Arrow"

# The name of the font
Font_Name = Font.default_name

# The size of the font
Font_Size = 16

#------------------------------------------------------------------------------
if Vampyr_Kernel.enabled?("Vampyr SBABS")
#------------------------------------------------------------------------------
Vampyr_Kernel.register("Vampyr HUD", 1.1, "12/06/2009")
#------------------------------------------------------------------------------
class Vampyr_HUD1 < Sprite
  
  def initialize(viewport)
    super(viewport)
    self.x, self.y = 1, 1
    @base   = Cache.system("Actor Base")
    @hpbar  = Cache.system("Actor HP Bar")
    @mpbar  = Cache.system("Actor MP Bar")
    @expbar = Cache.system("Actor Exp Bar")
    self.bitmap = Bitmap.new(156, 64)
    self.bitmap.font.name = Font_Name
    self.bitmap.font.size = Font_Size
    refresh
  end
  
  def update
    super
    self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
    update_opacity
    refresh if something_changed?
  end
  
  def refresh
    @actor = $game_party.members[0]
    return if @actor == nil
    @old_hp  = @actor.hp
    @old_mp  = @actor.mp
    @old_exp = @actor.exp
    self.bitmap.clear
    draw_hpbar(@actor, 0, 0)
    draw_mpbar(@actor, 0, 20)
    draw_expbar(@actor, 0, 40) if @actor.next_exp > 0
  end
  
  def draw_hpbar(actor, x, y)
    self.bitmap.draw_outlined_text(x, y, 24, Font_Size, Vocab::hp_a)
    rect = Rect.new(0, 0, @hpbar.width*actor.hp/actor.maxhp, @hpbar.height)
    self.bitmap.blt(x+24, y, @base, @base.rect)
    self.bitmap.blt(x+24, y, @hpbar, rect)
  end
  
  def draw_mpbar(actor, x, y)
    self.bitmap.draw_outlined_text(x, y, 24, Font_Size, Vocab::mp_a)
    rect = Rect.new(0, 0, @mpbar.width*actor.mp/actor.maxmp, @mpbar.height)
    self.bitmap.blt(x+24, y, @base, @base.rect)
    self.bitmap.blt(x+24, y, @mpbar, rect)
  end
  
  def draw_expbar(actor, x, y)
    self.bitmap.draw_outlined_text(x, y, 24, Font_Size, "Exp")
    rect = Rect.new(0, 0, @expbar.width*actor.current_exp/actor.next_exp, @expbar.height)
    self.bitmap.blt(x+24, y, @base, @base.rect)
    self.bitmap.blt(x+24, y, @expbar, rect)
  end
  
  def something_changed?
    return false if $game_party.members.size <= 0
    return true if @old_hp  != @actor.hp
    return true if @old_mp  != @actor.mp
    return true if @old_exp != @actor.exp
    return true if @actor   != $game_party.members[0]
    return false
  end
  
  def update_opacity
    if $game_player.screen_x <= (self.bitmap.width+16) and $game_player.screen_y <= (self.bitmap.height+16)
      self.opacity -= 10
    elsif self.opacity < 255
      self.opacity += 10
    end
  end
  
  def dispose
    self.bitmap.dispose
    super
  end
  
end

#------------------------------------------------------------------------------
class Vampyr_HUD2 < Sprite
  
  def initialize(viewport)
    super(viewport)
    @bg = Cache.system("Ammos Base")
    self.y = Graphics.height-@bg.height-(Font_Size/2)-1
    self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
    self.bitmap.font.name = Font_Name
    self.bitmap.font.size = Font_Size
    refresh
  end
  
  def update
    super
    self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
    update_opacity
    refresh if something_changed?
  end
  
  def refresh
    @actor = $game_party.members[0]
    return if @actor == nil
    @weapon1 = @actor.weapons[0]
    @weapon2 = @actor.weapons[1]
    @count1 = $game_party.item_number(@actor.ammos[@weapon1.id])
    @count2 = $game_party.item_number(@actor.ammos[@weapon2.id])
    self.bitmap.clear
    self.bitmap.blt(0, 10, @bg, @bg.rect)
    draw_ammos
  end
  
  def draw_ammos
    if @actor.weapons[0] != nil and @actor.ammos[@actor.weapons[0].id] != nil
      draw_icon(@actor.ammos[@actor.weapons[0].id].icon_index, 4, 14)
      self.bitmap.draw_outlined_text(0, self.bitmap.height-Font_Size, 32, Font_Size, @count1.to_s, 1)
    end
    if @actor.weapons[1] != nil and @actor.ammos[@actor.weapons[1].id] != nil
      draw_icon(@actor.ammos[@actor.weapons[1].id].icon_index, 36, 14)
    end
    self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Ammo_Text, 1)
  end
  
  def something_changed?
    return false if $game_party.members.size <= 0
    return true if @weapon1 != @actor.weapons[0]
    return true if @weapon2 != @actor.weapons[1]
    return true if @actor   != $game_party.members[0]
    return true if @count1  != $game_party.item_number(@actor.ammos[@weapon1.id])
    return true if @count2  != $game_party.item_number(@actor.ammos[@weapon2.id])
    return false
  end
  
  def update_opacity
    if $game_player.screen_x <= (self.bitmap.width+16) and $game_player.screen_y >= (Graphics.height-self.bitmap.height-16)
      self.opacity -= 10
    elsif self.opacity < 255
      self.opacity += 10
    end
  end
  
  def dispose
    self.bitmap.dispose
    super
  end
  
end

#------------------------------------------------------------------------------
class Vampyr_HUD3 < Sprite
  
  def initialize(viewport)
    super(viewport)
    @bg = Cache.system("Skills Base")
    self.x = Graphics.width-@bg.width
    self.y = Graphics.height-@bg.height-(Font_Size/2)-70
    self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
    self.bitmap.font.name = Font_Name
    self.bitmap.font.size = Font_Size
    refresh
  end
  
  def update
    super
    self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
    update_opacity
    refresh if something_changed?
  end
  
  def refresh
    @actor = $game_party.members[0]
    return if @actor == nil
    @hotkeys = {}
    @actor.skill_hotkeys.each { |k, v| @hotkeys[k] = v }
    self.bitmap.clear
    self.bitmap.blt(0, 10, @bg, @bg.rect)
    draw_skills
  end
  
  def draw_skills
    count = 0
    @actor.skill_hotkeys.sort.each { |key, value|
     next if value.nil?
     skill = $data_skills[value]
     next if skill.nil?
     draw_icon(skill.icon_index, 32*count+4, 14)
     self.bitmap.draw_outlined_text(32*count, self.bitmap.height-Font_Size, 32, Font_Size, Keys.name(key), 1)
     count += 1
    }
    self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Skills_Text, 1)
  end
  
  def something_changed?
    return false if $game_party.members.size <= 0
    return true if @actor != $game_party.members[0]
    return true if @hotkeys != @actor.skill_hotkeys
    return false
  end
  
  def update_opacity
    if $game_player.screen_x >= (Graphics.width-self.bitmap.width-16) and $game_player.screen_y >= (Graphics.height-self.bitmap.height-16)
      self.opacity -= 10
    elsif self.opacity < 255
      self.opacity += 10
    end
  end
  
  def dispose
    self.bitmap.dispose
    super
  end
  
end

#------------------------------------------------------------------------------
class Vampyr_HUD4 < Sprite
  
  def initialize(viewport)
    super(viewport)
    @bg = Cache.system("Items Base")
    self.x, self.y = Graphics.width-@bg.width, 1
    self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
    self.bitmap.font.name = Font_Name
    self.bitmap.font.size = Font_Size
    refresh
  end
  
  def update
    super
    self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
    update_opacity
    refresh if something_changed?
  end
  
  def refresh
    @actor = $game_party.members[0]
    return if @actor == nil
    @hotkeys = {}
    @actor.item_hotkeys.each { |k, v| @hotkeys[k] = v }
    self.bitmap.clear
    self.bitmap.blt(0, 10, @bg, @bg.rect)
    draw_items
  end
  
  def draw_items
    count = 0
    @actor.item_hotkeys.sort.each { |key, value|
     next if value.nil?
     item = $data_items[value]
     next if item.nil?
     draw_icon(item.icon_index, 32*count+4, 14)
     self.bitmap.draw_outlined_text(32*count, self.bitmap.height-Font_Size, 32, Font_Size, Keys.name(key), 1)
     count += 1
    }
    self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Items_Text, 1)
  end
  
  def something_changed?
    return false if $game_party.members.size <= 0
    return true if @actor != $game_party.members[0]
    return true if @hotkeys.to_s != @actor.item_hotkeys.to_s
    return false
  end
  
  def update_opacity
    if $game_player.screen_x >= (Graphics.width-self.bitmap.width-16) and $game_player.screen_y <= (self.bitmap.height+16)
      self.opacity -= 10
    elsif self.opacity < 255
      self.opacity += 10
    end
  end
  
  def dispose
    self.bitmap.dispose
    super
  end
  
end

#------------------------------------------------------------------------------
class Spriteset_Map
  
  alias vampyr_hud_initialize initialize
  alias vampyr_hud_update update
  alias vampyr_hud_dispose dispose
  
  def initialize
    $vampyr_hud1 = Vampyr_HUD1.new(@viewport3)
    $vampyr_hud2 = Vampyr_HUD2.new(@viewport3) if Show_Ammos
    $vampyr_hud3 = Vampyr_HUD3.new(@viewport3) if Show_Skills
    $vampyr_hud4 = Vampyr_HUD4.new(@viewport3) if Show_Items
    vampyr_hud_initialize
  end
  
  def update
    vampyr_hud_update
    $vampyr_hud1.update
    $vampyr_hud2.update if Show_Ammos
    $vampyr_hud3.update if Show_Skills
    $vampyr_hud4.update if Show_Items
  end
  
  def dispose
    vampyr_hud_dispose
    $vampyr_hud1.dispose
    $vampyr_hud2.dispose if Show_Ammos
    $vampyr_hud3.dispose if Show_Skills
    $vampyr_hud4.dispose if Show_Items
  end
  
end

#------------------------------------------------------------------------------
end
Titanhex
Bump. Seems like a very simple question with a simple enough answer.
Night5h4d3
Well, I can't say for sure, but in theory, supposing you're using viewport3 for the static image.. Near the bottom of the script you'll see
vampyr_hud_initialize
directly above that try putting:
CODE
$vampyr_hud1.z = 700
$vampyr_hud2.z = 701
$vampyr_hud3.z = 702
$vampyr_hud4.z = 703


If you have a viewport4 or something higher for your static pictures, do the above and in the 4 lines above that change "@viewport3" to the viewport of the static images. This is only in theory, I'm unable to actually check it right now.
Titanhex
Thanks, that did it.

I've now learned what the .z function is. I didn't know it was picture layer, I always thought it was how zoomed in a picture was.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.