#============================================================================== # ** 地图显示变量 v1.2 # 作者:945127391 # 使用说明: # ①新建一个显示变量的精灵: # 事件 -> 脚本中输入: # $game_map.new_variable_sprite(id, x, y, ini_var, [text_bitmap]) # id - 要创建的变量精灵的ID # x - 要创建的变量精灵的X坐标 # y - 要创建的变量精灵的Y坐标 # ini_var - 要创建的变量精灵初始显示的数值 # text_bitmap - 要创建的变量精灵的文字图片文件 # 可以省略,如果为nil,则不用图片描绘文字; # 默认为nil # ②删除一个显示变量的精灵: # 事件 -> 脚本中输入: # $game_map.map_variables[id] = nil # id - 要删除的变量精灵的ID # ③改变一个变量精灵的属性: # (以下的 id 都是要改变的变量精灵的ID) # $game_map.map_variables[id].x = n # 改变id号变量精灵的X坐标 # $game_map.map_variables[id].y = n # 改变id号变量精灵的Y坐标 # $game_map.map_variables[id].variable = n # 改变id号变量精灵的显示的变量 # $game_map.map_variables[id].opacity = n # 改变id号变量精灵的不透明 # 度(0~255) # $game_map.map_variables[id].visible = true/false # 改变id号变量精灵的可 # 见状态,true为可见,false为不可见 # $game_map.map_variables[id].text_bitmap = bitmap # 改变文字图片 # 以下是用来改变变量精灵的字体的: # $game_map.map_variables[id].font[:name] # $game_map.map_variables[id].font[:size] # $game_map.map_variables[id].font[:bold] # $game_map.map_variables[id].font[:italic] # $game_map.map_variables[id].font[:shadow] # $game_map.map_variables[id].font[:outline] # $game_map.map_variables[id].font[:color] # $game_map.map_variables[id].font[:out_color] #============================================================================== #------------------------------------------------------------------------------ # ** Bitmap #------------------------------------------------------------------------------ class Bitmap #---------------------------------------------------------------------------- # * 描绘图片数字 #---------------------------------------------------------------------------- def draw_bitmap_number(bitmap, x, y, number) number = number.to_s aw = bitmap.width / 10 l = aw * number.size b = Bitmap.new(l, bitmap.height) for i in 0...number.size src_rect = Rect.new(aw * number[i].to_i, 0, aw, bitmap.height) b.blt(aw * i, 0, bitmap, src_rect) end blt(x, y, b, b.rect) b.dispose end end #------------------------------------------------------------------------------ # ** Sprite_Variable #------------------------------------------------------------------------------ class Sprite_Variable < Sprite_Base #---------------------------------------------------------------------------- # * 初始化 #---------------------------------------------------------------------------- def initialize(id) super(nil) @id = id self.x = $game_map.map_variables[@id].x self.y = $game_map.map_variables[@id].y self.z = 9999 self.bitmap = Bitmap.new(Graphics.width - self.x, Graphics.height - self.y) self.opacity = $game_map.map_variables[@id].opacity self.visible = $game_map.map_variables[@id].visible refresh end #---------------------------------------------------------------------------- # * 更新 #---------------------------------------------------------------------------- def update super self.x = $game_map.map_variables[@id].x self.y = $game_map.map_variables[@id].y self.bitmap = Bitmap.new(Graphics.width - self.x, Graphics.height - self.y) self.opacity = $game_map.map_variables[@id].opacity self.visible = $game_map.map_variables[@id].visible refresh end #---------------------------------------------------------------------------- # * 更新内容 #---------------------------------------------------------------------------- def refresh self.bitmap.clear if $game_map.map_variables[@id].text_bitmap == nil self.bitmap.font.name = $game_map.map_variables[@id].font[:name] self.bitmap.font.size = $game_map.map_variables[@id].font[:size] self.bitmap.font.bold = $game_map.map_variables[@id].font[:bold] self.bitmap.font.italic = $game_map.map_variables[@id].font[:italic] self.bitmap.font.shadow = $game_map.map_variables[@id].font[:shadow] self.bitmap.font.outline = $game_map.map_variables[@id].font[:outilne] self.bitmap.font.color = $game_map.map_variables[@id].font[:color] self.bitmap.font.out_color = $game_map.map_variables[@id].font[:out_color] p self.bitmap.rect self.bitmap.draw_text(0, 0, self.bitmap.width, self.bitmap.text_size("1").height, $game_map.map_variables[@id].variable) else self.bitmap.draw_bitmap_number($game_map.map_variables[@id].text_bitmap, 0, 0, $game_map.map_variables[@id].variable) end end end #------------------------------------------------------------------------------ # ** Game_MapVariable #------------------------------------------------------------------------------ class Game_MapVariable #---------------------------------------------------------------------------- # * 定义实例变量 #---------------------------------------------------------------------------- attr_reader :id attr_accessor :x attr_accessor :y attr_accessor :text_bitmap attr_accessor :font attr_accessor :variable attr_accessor :opacity attr_accessor :visible #---------------------------------------------------------------------------- # * 初始化 #---------------------------------------------------------------------------- def initialize(id, x, y, ini_var, text_bitmap=nil) @id = id @x = x @y = y @text_bitmap = text_bitmap @variable = ini_var @font = { :name => Font.default_name, :size => Font.default_size, :bold => Font.default_bold, :italic => Font.default_italic, :shadow => Font.default_shadow, :outline => Font.default_outline, :color => Font.default_color, :out_color => Font.default_out_color } @opacity = 255 @visible = true end end #------------------------------------------------------------------------------ # ** Game_Map #------------------------------------------------------------------------------ class Game_Map #---------------------------------------------------------------------------- # * 定义实例变量 #---------------------------------------------------------------------------- attr_accessor :map_variables #---------------------------------------------------------------------------- # * 重命名方法 #---------------------------------------------------------------------------- alias oi initialize #---------------------------------------------------------------------------- # * 初始化 #---------------------------------------------------------------------------- def initialize oi @map_variables = [] end #---------------------------------------------------------------------------- # * 新建变量精灵 #---------------------------------------------------------------------------- def new_variable_sprite(id, x, y, ini_var, text_bit=nil) if @map_variables[id] != nil @map_variables[id] = nil end @map_variables[id] = Game_MapVariable.new(id, x, y, ini_var, text_bit) end #---------------------------------------------------------------------------- # * 删除变量精灵 #---------------------------------------------------------------------------- def del_variable_sprite(id) @map_variables.delete_at(id) end end #------------------------------------------------------------------------------ # ** Scene_Map #------------------------------------------------------------------------------ class Scene_Map < Scene_Base #---------------------------------------------------------------------------- # * 重命名方法 #---------------------------------------------------------------------------- alias os start alias ou update #---------------------------------------------------------------------------- # * 开始处理 #---------------------------------------------------------------------------- def start os @map_variable_sprites = [] end #---------------------------------------------------------------------------- # * 释放 #---------------------------------------------------------------------------- def dispose super for i in [email]0...@map_variable_sprites.size[/email] @map_variable_sprites.dispose if @map_variable_sprites.is_a?(Sprite) end end #---------------------------------------------------------------------------- # * 刷新画面 #---------------------------------------------------------------------------- def update ou for i in 0...$game_map.map_variables.size if $game_map.map_variables[i] != nil and @map_variable_sprites[i] == nil @map_variable_sprites[i] = Sprite_Variable.new(i) elsif $game_map.map_variables[i] == nil and @map_variable_sprites[i] != nil @map_variable_sprites[i].dispose end end for i in [email]0...@map_variable_sprites.size[/email] @map_variable_sprites[i].update if $game_map.map_variables[i] != nil and @map_variable_sprites[i].is_a?(Sprite) end end end
class Scene_Map < Scene_Base alias tm_20140809 terminate def terminate @map_variable_sprites.each {|s| s.dispose if s } tm_20140809 end end
QQ图片20140819105835.jpg (6.78 KB, 下载次数: 43)
2b274324ab18972b7e11c513e4cd7b899f510af6.png (78.79 KB, 下载次数: 46)
4a0479fa828ba61ed3d20df64334970a314e59d9.png (148.83 KB, 下载次数: 42)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |