加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 zeldafd 于 2013-8-26 11:44 编辑
我做了個新的HUD系統, 但運行時第47行一直報錯, 說"UNDEFINED METHOD 'bitmap' FOR nil:NilClass"
我以為是我用了實例變量的問題, 但我全部用了全局後都是一樣.
以下是我的HUD的腳本, 請各路人士幫忙看一下是什麼一回事...
class Game_Hud $game_hud = Game_Hud.new def initialize create_hp create_sp end def create_hp $hp_slot = Sprite.new $hp_slot.bitmap = Cache.system($HP_SLOT) $hp_slot.x = 5 $hp_slot.y = 15 $hp_slot.z = 85 $hp_meter_image = Cache.system($HP_METER) # hp計的圖 $hp_meter_sprite = Sprite.new $hp_meter_sprite.bitmap = Bitmap.new($hp_meter_image.width, $hp_meter_image.height) # HP血條位置資訊 $hp_meter_sprite.x = 35 $hp_meter_sprite.y = 15 $hp_meter_sprite.z = 90 end def create_sp $sp_slot = Sprite.new $sp_slot.bitmap = Cache.system($SP_SLOT) $sp_slot.x = 5 $sp_slot.y = 45 $sp_slot.z = 85 $sp_meter_image = Cache.system($SP_METER) # sp計的圖 $sp_meter_sprite = Sprite.new $sp_meter_sprite.bitmap = Bitmap.new($sp_meter_image.width, $sp_meter_image.height) # SP血條位置資訊 $sp_meter_sprite.x = 35 $sp_meter_sprite.y = 44 $sp_meter_sprite.z = 90 end def update_hp $hp_meter_sprite.bitmap.clear $hp_meter_sprite.bitmap.blt(0, 0, $hp_meter_image, Rect.new(0, 0, $hp_meter_image.width, $hp_meter_image.height) ) end def update_sp $sp_meter_sprite.bitmap.clear $sp_meter_sprite.bitmap.blt(0, 0, $sp_meter_image, Rect.new(0, 0, $sp_meter_image.width, $sp_meter_image.height)) end def dispose $hp_meter_sprite.bitmap.dispose $hp_meter_sprite.dispose $hp_slot.bitmap.dispose $hp_slot.dispose $sp_meter_sprite.bitmap.dispose $sp_meter_sprite.dispose $sp_slot.bitmap.dispose $sp_slot.dispose end def setVisiable(trueorfalse) v = trueorfalse end def update update_hp update_sp end def refresh dispose initialize end end class Spriteset_Map alias old_init initialize def initialize $game_hud old_init end alias old_dispose dispose def dispose $game_hud.dispose old_dispose end alias old_update update def update $game_hud.update old_update end alias old_refresh_char refresh_characters def refresh_characters old_refresh_hud $game_hud.refresh end end
class Game_Hud
$game_hud = Game_Hud.new
def initialize
create_hp
create_sp
end
def create_hp
$hp_slot = Sprite.new
$hp_slot.bitmap = Cache.system($HP_SLOT)
$hp_slot.x = 5
$hp_slot.y = 15
$hp_slot.z = 85
$hp_meter_image = Cache.system($HP_METER) # hp計的圖
$hp_meter_sprite = Sprite.new
$hp_meter_sprite.bitmap = Bitmap.new($hp_meter_image.width, $hp_meter_image.height)
# HP血條位置資訊
$hp_meter_sprite.x = 35
$hp_meter_sprite.y = 15
$hp_meter_sprite.z = 90
end
def create_sp
$sp_slot = Sprite.new
$sp_slot.bitmap = Cache.system($SP_SLOT)
$sp_slot.x = 5
$sp_slot.y = 45
$sp_slot.z = 85
$sp_meter_image = Cache.system($SP_METER) # sp計的圖
$sp_meter_sprite = Sprite.new
$sp_meter_sprite.bitmap = Bitmap.new($sp_meter_image.width, $sp_meter_image.height)
# SP血條位置資訊
$sp_meter_sprite.x = 35
$sp_meter_sprite.y = 44
$sp_meter_sprite.z = 90
end
def update_hp
$hp_meter_sprite.bitmap.clear
$hp_meter_sprite.bitmap.blt(0, 0, $hp_meter_image,
Rect.new(0, 0, $hp_meter_image.width, $hp_meter_image.height) )
end
def update_sp
$sp_meter_sprite.bitmap.clear
$sp_meter_sprite.bitmap.blt(0, 0, $sp_meter_image,
Rect.new(0, 0, $sp_meter_image.width, $sp_meter_image.height))
end
def dispose
$hp_meter_sprite.bitmap.dispose
$hp_meter_sprite.dispose
$hp_slot.bitmap.dispose
$hp_slot.dispose
$sp_meter_sprite.bitmap.dispose
$sp_meter_sprite.dispose
$sp_slot.bitmap.dispose
$sp_slot.dispose
end
def setVisiable(trueorfalse)
v = trueorfalse
end
def update
update_hp
update_sp
end
def refresh
dispose
initialize
end
end
class Spriteset_Map
alias old_init initialize
def initialize
$game_hud
old_init
end
alias old_dispose dispose
def dispose
$game_hud.dispose
old_dispose
end
alias old_update update
def update
$game_hud.update
old_update
end
alias old_refresh_char refresh_characters
def refresh_characters
old_refresh_hud
$game_hud.refresh
end
end
|