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.

Turning a HUD on/off with switch?

Hi,

I have the Kingdom Hearts HUD script

and would like to be able to turn it on/off using a switch.

is that possible?

Thanks

Kingdom HUD script
Code:
#==============================================================================
# â–  Kingdom Hearts HUD
#------------------------------------------------------------------------------
# by Skive
# skivedaft@yahoo.com
#
# --
#
# released on 5th March 2006
#==============================================================================

#==============================================================================
# â–  Sprite_HP
#------------------------------------------------------------------------------
#  the HUD's hp bar
#==============================================================================

class Sprite_HP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
 
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
draw_bar(20, 6)
self.angle = 270
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @hp != @actor.hp or @maxhp != @actor.maxhp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
    
max = (@actor.hp * 360) / @actor.maxhp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(150, 0, 0)
when 2
color = Color.new(170, 0, 0)
when 3
color = Color.new(190, 0, 0)
when 4
color = Color.new(210, 0, 0)
when 5
color = Color.new(230, 0, 0)
when 6
color = Color.new(255, 0, 0)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end

#==============================================================================
# â–  Sprite_SP
#------------------------------------------------------------------------------
#  the HUD's sp bar
#==============================================================================

class Sprite_SP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
draw_bar(20, 6) #20,6
self.angle = 90
self.mirror = true
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @sp != @actor.sp or @maxsp != @actor.maxsp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
max = (@actor.sp * 360) / @actor.maxsp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(29, 82, 112)
when 2
color = Color.new(29, 86, 120)
when 3
color = Color.new(28, 90, 131)
when 4
color = Color.new(27, 96, 144)
when 5
color = Color.new(26, 102, 156)
when 6
color = Color.new(26, 106, 167)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end

#==============================================================================
# â–  Sprite_HUD
#------------------------------------------------------------------------------
#  draws the HUD on the map
#==============================================================================

class Sprite_HUD < Sprite
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(corner = 4)
super(nil)
self.z = 200
for actor in $game_party.actors
next if actor.dead?
@actor = actor
@actor_index = $game_party.actors.index(@actor)
break
end
@hp_sprite = Sprite_HP.new(@actor)
@sp_sprite = Sprite_SP.new(@actor)
self.bitmap = Bitmap.new(375, 220)
case corner
when 1
x = 16
y = 16
when 2
x = 640 - 52 - 16
y = 16
when 3
x = 320
y = 20
when 4
x = 170
y = 415

xh = 295
yh= 415
end
self.x = x
self.y = y
@hp_sprite.x = xh + 19   # + 27
@hp_sprite.y = yh + 9    #3
@sp_sprite.x = xh + 32 - 1    #27-1
@sp_sprite.y = yh + 68  #3-1+ 60
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?

bitmap = RPG::Cache.picture("background")
self.bitmap.blt(0, 10, bitmap, Rect.new(0, 0, 375, 220))


end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
@hp_sprite.update
@sp_sprite.update
if @actor != $game_party.actors[@actor_index]
@actor = $game_party.actors[@actor_index]
@hp_sprite.actor = @actor
@sp_sprite.actor = @actor
@hp_sprite.refresh
@sp_sprite.refresh
refresh
end
end
end

#==============================================================================
# â–  Scene_Map
#------------------------------------------------------------------------------
#  draws the hud on the map screen
# @khhud_corner is the corner you want the hud to be displayed in.
# 1 is upper left, 2 is upper right, 3 is bottom left and 4 is bottom right
#==============================================================================

class Scene_Map
alias main_khhud main
alias update_khhud update
alias transfer_khhud transfer_player
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize
@khhud_corner = 4 # 1 or 2 or 3 or 4
end
#--------------------------------------------------------------------------
# ● main
#--------------------------------------------------------------------------
def main
@hud = Sprite_HUD.new(@khhud_corner)
main_khhud
@hud.dispose
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
@hud.update
update_khhud
end
end
 
This might work, but I dunno how .visible works with sprites.

#=================================
class Scene_Map
alias wyatt_edit_update update
def update
if $game_switches[EDITHERE]
@hud.visible = true
else
@hud.visible = false
end
wyatt_edit_update
end
end
#=================================

Add it somewhere below that script, and change the words "EDITHERE" to the number of the switch.
 
.visible works with sprites. Now that's confirmed. The script's fine, there can't be any errors if the @hud object exists, and it does, so if you still get an error it can't be caused by Wyatt's script.
 

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