Я устал. Писать. Этот. Скрипт.
Скрипт на HUD элемент в игре.
Проблема в его некорректном отображении и я не могу это исправить.
Сам скрипт:
#===============================================================================
# My HUD interfeice based on RienoRPG HUD
#===============================================================================
#===============================================================================
# Settings
#===============================================================================
#======#======#======#======#======#======#======#======#======#======#======#==
#===============================================================================
# ** My_HUD_Settings
#===============================================================================
module My_HUD_Settings
#=============================================================================
# * General settings of HUD
#=============================================================================
#-----------------------------------------------------------------------------
# Get graphis for the HUD
#-----------------------------------------------------------------------------
HUD_back = "pop.png"
HP_bar = "HP.png"
#-----------------------------------------------------------------------------
Speed = 30 # Speed to FadeIn/FadeOut
$HUD_Opacity = 255 # Final 0pacity of the HUD
#-----------------------------------------------------------------------------
# Get HUD switch
# Switch that controls whether the HUD is active or not HUD to be active ON
# and OFF to turn it off.
#-----------------------------------------------------------------------------
Switch_Control = 1
#-----------------------------------------------------------------------------
# Get the character
# The number of character in order according to menu. 0 number is the first
# character
#-----------------------------------------------------------------------------
Number_Character = 0
#=============================================================================
# * Settings of HUD Elements
#=============================================================================
#-----------------------------------------------------------------------------
# Get points of HUD back
# Post nil if you want to center on screen
#-----------------------------------------------------------------------------
Position_X = 0
Position_Y = 0
#-----------------------------------------------------------------------------
# Get points of HP graphics
# Set true to show the bar that represents the character's HP (false to not
# display)
#-----------------------------------------------------------------------------
HP_X = 46
HP_Y = 26
#-----------------------------------------------------------------------------
# Get points of values of HP for HUD
# Set true to show the value of Current HP bar (false to not display)
# Set true to show the maximum value of the HP bar (false to not display)
#-----------------------------------------------------------------------------
Values_HP_X = 0
Values_HP_Y = 0
#-----------------------------------------------------------------------------
# Set style of HP
# Font to use, write nil to use the default
#-----------------------------------------------------------------------------
Values_HP_Color = Color.new(255,255,255)
Values_HP_Font = nil
Values_HP_Size_of_Font = 15
end
#===============================================================================
# ** Cache
#===============================================================================
module Cache
#=============================================================================
# * Get HUD Graphic
# filename : Filename
#=============================================================================
def self.hud(filename)
load_bitmap("Graphics/Hud/", filename)
end
end
#===============================================================================
# End of Settings
#===============================================================================
#===============================================================================
# HUD Script
#===============================================================================
#======#======#======#======#======#======#======#======#======#======#======#==
class Scene_Base
include My_HUD_Settings
alias hud_update update
#=============================================================================
# * Start
#=============================================================================
def hud_start
$hud_keyboard_switch = true
active_hud
update_infos
end
#=============================================================================
# * Active HUD
#=============================================================================
def active_hud
unless @hud_has_run_before
$game_switches[Switch_Control] = true
@hud_has_run_before = true
end
@back = Sprite.new
@back.bitmap = Cache.hud(HUD_back)
@back.opacity = $HUD_Opacity
@back.x = Position_X
@back.y = Position_Y
w = @back.width
h = @back.height
@back.z = 190
@hp = Sprite.new
@hp.bitmap = Cache.hud(HP_bar)
hpwidth = @hp.width
@hp.x = HP_X
@hp.y = HP_Y
@hp.z = 191
@hp.opacity = $HUD_Opacity
@hp_val = Sprite.new
@hp_val.bitmap = Bitmap.new(600,600)
@hp_val.opacity = $HUD_Opacity
@hp_val.x = Values_HP_X
@hp_val.y = Values_HP_Y
@hp_val.z = 192
@id = Number_Character
@info = []
hud_real_update if status_update
end
#=============================================================================
# * Terminate
#=============================================================================
def hud_terminate
$hud_keyboard_switch = false
if @back != nil
@back.bitmap.dispose
@back.dispose
end
if @hp != nil
@hp.bitmap.dispose
@hp.dispose
end
if @hp_val != nil
@hp_val.bitmap.dispose
@hp_val.dispose
end
end
#=============================================================================
# * Update
#=============================================================================
def update
if $game_switches[Switch_Control] == true and $hud_keyboard_switch
if @back != nil or if @hp != nil or @hp_val != nil
if @back.opacity != $HUD_Opacity
@back.opacity = $HUD_Opacity
end
if @hp.opacity != $HUD_Opacity
@hp.opacity = $HUD_Opacity
end
if @hp_val.opacity != $HUD_Opacity
@hp_val.opacity = $HUD_Opacity
end
end
else
active_hud
end
else
if @back != nil
@back.bitmap.dispose
@back.dispose
@back = nil
end
if @hp != nil
@hp.bitmap.dispose
@hp.dispose
@hp = nil
end
if @hp_val != nil
@hp_val.bitmap.dispose
@hp_val.dispose
@hp_val = nil
end
end
# Если игрок забрел под HUD
if @back != nil
# Если игрок между координатами HUD
if $game_player.screen_x >= @back.x and $game_player.screen_x <= @back.x + @back.width and
$game_player.screen_y >= @back.y and $game_player.screen_y <= @back.y + @back.height
# То установим прозрачность из настроек так, чтобы видеть персонажа
@back.opacity = 125
@hp.opacity = 125
@hp_val.opacity = 125
end
end
hud_real_update if status_update
hud_check_key_toggle
hud_update
end
#=============================================================================
# HUD Real Update
#=============================================================================
def hud_real_update
a = $game_party.members[@id]
@hp.bitmap.dispose
@hp.bitmap = Cache.hud(HP_bar)
@hp.bitmap.clear_rect(Rect.new((@hp.width*a.hp/a.mhp),0,@hp.width,@hp.height))
text = a.hp.to_s + "/" + a.mhp.to_s
@hp_val.bitmap.dispose
@hp_val.bitmap = Bitmap.new(600,600)
@hp_val.opacity = $HUD_Opacity
@hp_val.x = Values_HP_X
@hp_val.y = Values_HP_Y
@hp_val.z = 192
@hp_val.bitmap.font.size = 14
@hp_val.bitmap.draw_text(12, 15, 180, 15, text, 2)
text = nil
end
#=============================================================================
# Status Update
#=============================================================================
def status_update
return false if @hp_val == nil
return false if @hp == nil
a = $game_party.members[@id]
return update_infos if a.id != @info[0]
return update_infos if a.character_index != @info[2]
return update_infos if a.hp != @info[6]
return update_infos if a.mhp != @info[7]
return false
end
#=============================================================================
# Update Infos
#=============================================================================
def update_infos
a = $game_party.members[@id]
@info[0] = a.id
@info[2] = a.character_index
@info[6] = a.hp
@info[7] = a.mhp
return true
end
#=============================================================================
# Check HUD toggle key
#=============================================================================
def hud_check_key_toggle
$hud_keyboard_switch = true if $hud_keyboard_switch.nil?
if Input.trigger?(:L)
$hud_keyboard_switch = !$hud_keyboard_switch
end
end
end
#===============================================================================
# END of HUD Script
#===============================================================================
#===============================================================================
#===============================================================================
# ** Scene Map
#===============================================================================
class Scene_Map < Scene_Base
alias h_start start
def start
hud_start
h_start
end
def terminate
super
hud_terminate
#прерываем показ худа чтобы сделать снимок экрана
SceneManager.snapshot_for_background
hud_start if !SceneManager.scene_is?(Scene_Save)
dispose_spriteset
perform_battle_transition if SceneManager.scene_is?(Scene_Battle)
end
end
#==============================================================================
# ** Scene_End
#==============================================================================
class Scene_End < Scene_MenuBase
alias h_terminate command_to_title
def command_to_title
hud_terminate
h_terminate
end
end
В силу специфичности моего меню мне нужно:
1) чтобы худ отображался в игре, при открытии меню персонажа, в инвентаре и при переходе к завершению игры (команда shutdown в меню персонажа)
2) чтобы при переходе на экран сохранения худ исчезал, ровно как и при переходе на экран загрузки и при возвращении на титульный экран.
3) При загрузке худ вновь нормально отображался
Графика для худа:
должна лежать в папке с проектом в папке с графикой, в папе "Hud"