Project1

标题: 請問自定義新變量的調用 [打印本页]

作者: sai90306    时间: 2012-4-9 23:34
标题: 請問自定義新變量的調用
以下是我在http://rpg.blue/thread-225983-1-1.html
提問時end55rpg大大替我寫的自定義變量腳本(由衷感謝!!)

(抱歉沒有用代碼框...因為用代碼框發出來的帖會整個白白一片)
class Game_Actor < Game_Battler
      #--------------------------------------------------------------------------
    class Game_Actor < Game_Battler
      #--------------------------------------------------------------------------
      # ● 定义实例变量
      #--------------------------------------------------------------------------
      attr_accessor   :友好度                     # 友好度变量
      #--------------------------------------------------------------------------
      # ● 设置
      #     actor_id : 角色 ID
      #--------------------------------------------------------------------------
    alias old_s setup
    def setup(actor_id)
       old_s(actor_id)
       @友好度 = @友好度.to_i
    end
    end

如果想將這個字定義的變量(友好度)在Window_Status裡面顯示出來請問能夠做到嗎?
以下Window_Status的部分CODE...
# ● 初始化目標
  #     actor : 角色
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    @actor = actor
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_actor_graphic(@actor, 40, 112)
    draw_actor_name(@actor, 4, 0)
    draw_actor_class(@actor, 4 + 144, 0)
    draw_actor_level(@actor, 96, 32)
    draw_actor_state(@actor, 96, 64)
    draw_actor_hp(@actor, 96, 112, 172)
    draw_actor_sp(@actor, 96, 144, 172)
    draw_actor_parameter(@actor, 96, 192, 0)
    draw_actor_parameter(@actor, 96, 224, 1)
    draw_actor_parameter(@actor, 96, 256, 2)
    draw_actor_parameter(@actor, 96, 304, 3)
    draw_actor_parameter(@actor, 96, 336, 4)
    draw_actor_parameter(@actor, 96, 368, 5)
    draw_actor_parameter(@actor, 96, 400, 6)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 48, 80, 32, "EXP")
    self.contents.draw_text(320, 80, 80, 32, "NEXT")
    self.contents.font.color = normal_color
    self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
    self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 160, 96, 32, "裝備")
    draw_item_name($data_weapons[@actor.weapon_id], 320 + 16, 208)
    draw_item_name($data_armors[@actor.armor1_id], 320 + 16, 256)
    draw_item_name($data_armors[@actor.armor2_id], 320 + 16, 304)
    draw_item_name($data_armors[@actor.armor3_id], 320 + 16, 352)
    draw_item_name($data_armors[@actor.armor4_id], 320 + 16, 400)
  end
觀察後猜測...
不知道是不是用"draw_actor_友好度(@actor, XX, YY)"來實現?dsu_plus_rewardpost_czw
作者: zhangbanxian    时间: 2012-4-10 08:53
本帖最后由 zhangbanxian 于 2012-4-10 08:54 编辑

- -b话说这@友好度 = @友好度.to_i干嘛的?好歹也得是@友好度 = 0...(这句作用是赋初始值)
你要draw_actor_友好度(@actor, XX, YY)"的话,得自己写个函数,比如
  1. def draw_actor_友好度(actor, x, y)
  2. self.contents.draw_text(x, y, 80, 32,actor.友好度.to_s)
  3. end
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1