Project1

标题: 显示战斗头像脚本和召唤技能的 冲突 求解! [打印本页]

作者: gkl0510    时间: 2014-8-3 12:16
标题: 显示战斗头像脚本和召唤技能的 冲突 求解!
本帖最后由 RyanBern 于 2014-8-3 13:32 编辑

在游戏中用了显示战斗头像的脚本,原本没有问题。
但后来用事件加了一个召唤兽的技能以后,问题就来了。

战斗的时候没问题



但是战斗结束以后就会报错



尝试给召唤兽加一个头像也无济于事。
猜测是不是因为“显示战斗头像”的脚本在进入战斗的一开始
就加入了头像然后结束就会消除头像,
但是召唤兽是在半途中加入的,所以结束的时候消除头像
会出现bug?

由于看不懂ruby代码,纯粹是在瞎猜,还望各位大神指点
多谢!


可以直接下游戏工程体验一下……


游戏工程下载地址

http://pan.baidu.com/s/1xWieE


显示战斗头像脚本如下
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================

  4. # ————————————————————————————————————
  5. # ▼▲▼ XRXS_BP 7. バトルステータス?クリアデザイン ver.1.03 ▼▲▼
  6. # by 桜雅 在土
  7. #==============================================================================
  8. # ■ Window_BattleStatus
  9. #==============================================================================
  10. class Window_BattleStatus < Window_Base
  11. #--------------------------------------------------------------------------
  12. # ● 公開インスタンス変数
  13. #--------------------------------------------------------------------------
  14. attr_accessor :update_cp_only # CPメーターのみの更新
  15. #--------------------------------------------------------------------------
  16. # ● オブジェクト初期化
  17. #--------------------------------------------------------------------------
  18. alias xrxs_bp7_initialize initialize
  19. def initialize
  20. # 初期化
  21. @previous_hp = []
  22. @previous_sp = []
  23. # 呼び戻す
  24. xrxs_bp7_initialize
  25. ##############################修改############################################
  26. @sta_back = []
  27. for actor_index in 1..$game_party.actors.size
  28.   actor = $game_party.actors[actor_index - 1]
  29. @sta_back[actor_index] = Sprite.new
  30. @sta_back[actor_index].bitmap = Bitmap.new("Graphics/Characters/Heads/"+ actor.name + ".png")
  31. @sta_back[actor_index].x = (actor_index- 1)* 160 - 5 #在这里调整图片x坐标
  32. @sta_back[actor_index].y = 243#在这里调整图片y坐标
  33. @sta_back[actor_index].z = self.z+1#在这里调整图片优先级
  34. end
  35. ##############################修改############################################
  36. # ↓Full-Viewの場合は下二行の # を消してください。
  37. #self.opacity = 0
  38. #self.back_opacity = 0
  39. ##############################修改############################################
  40. refresh
  41. ##############################修改############################################
  42. end
  43. ##############################修改############################################
  44. def dispose
  45.    super  
  46.    for actor_index in 1..$game_party.actors.size
  47.       @sta_back[actor_index].bitmap.dispose
  48.       @sta_back[actor_index].dispose
  49.    end
  50. end
  51. ##############################修改############################################
  52. #--------------------------------------------------------------------------
  53. # ● リフレッシュ
  54. #--------------------------------------------------------------------------
  55. alias xrxs_bp7_refresh refresh
  56. def refresh
  57. # CPメーターの更新のみ の場合
  58. if @update_cp_only
  59. xrxs_bp7_refresh
  60. return
  61. end
  62. # 変更するものがない場合、飛ばす
  63. @item_max = $game_party.actors.size
  64. bool = false
  65. for i in 0...@item_max
  66. actor = $game_party.actors[i]
  67. if (@previous_hp[i] != actor.hp) or (@previous_sp[i] != actor.sp)
  68. bool = true
  69. end
  70. end
  71. return if bool == false
  72. # 描写を開始
  73. self.contents.clear
  74. for i in 0...@item_max
  75. actor = $game_party.actors[i]
  76. actor_x = i * 160 + 29
  77. # 歩行キャラグラフィックの描写
  78. #draw_actor_graphic(actor, actor_x - 9, 116)

  79. # HP/SPメーターの描写
  80. draw_actor_hp_meter_line(actor, actor_x, 47, 96, 12)
  81. draw_actor_sp_meter_line(actor, actor_x, 79, 96, 12)
  82. # HP数値の描写
  83. self.contents.font.size = 24 # HP/SP数値の文字の大きさ
  84. self.contents.font.color = Color.new(0,0,0,192)
  85. self.contents.draw_text(actor_x, 35, 96, 24, actor.hp.to_s, 2)
  86. self.contents.font.color = actor.hp == 0 ? knockout_color :
  87. actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
  88. self.contents.draw_text(actor_x-2, 33, 96, 24, actor.hp.to_s, 2)
  89. # SP数値の描写
  90. self.contents.font.color = Color.new(0,0,0,192)
  91. self.contents.draw_text(actor_x, 72, 96, 24, actor.sp.to_s, 2)
  92. self.contents.font.color = actor.sp == 0 ? knockout_color :
  93. actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
  94. self.contents.draw_text(actor_x-2, 70, 96, 24, actor.sp.to_s, 2)
  95. # 用語「HP」と用語「SP」の描写
  96. self.contents.font.size = 20 # 用語「HP/SP」の文字の大きさ
  97. draw_actor_name(actor, actor_x ,3 )

  98. self.contents.font.color = Color.new(0,0,0,192)
  99. self.contents.draw_text(actor_x+2, 27, 196, 24, $data_system.words.hp)
  100. self.contents.draw_text(actor_x+2, 59, 196, 24, $data_system.words.sp)
  101. self.contents.font.color = system_color # 用語「HP/SP」の文字の色
  102. self.contents.draw_text(actor_x, 25, 196, 24, $data_system.words.hp)
  103. self.contents.draw_text(actor_x, 57, 196, 24, $data_system.words.sp)
  104. draw_actor_state(actor, actor_x, 100)
  105. # 値を更新
  106. @previous_hp[i] = actor.hp
  107. @previous_hp[i] = actor.hp
  108. end
  109. end
  110. end
  111. #==============================================================================
  112. # ■ Window_Base
  113. #==============================================================================
  114. class Window_Base < Window
  115. #--------------------------------------------------------------------------
  116. # ● HPメーター の描画
  117. #--------------------------------------------------------------------------
  118. def draw_actor_hp_meter_line(actor, x, y, width = 156, height = 4)
  119. w = width * actor.hp / [actor.maxhp,1].max
  120. hp_color_1 = Color.new(255, 0, 0, 192)
  121. hp_color_2 = Color.new(255, 255, 0, 192)
  122. self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  123. draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  124. x -= 1
  125. y += (height/4).floor
  126. self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  127. draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  128. x -= 1
  129. y += (height/4).ceil
  130. self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  131. draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  132. x -= 1
  133. y += (height/4).ceil
  134. self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  135. draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  136. end
  137. #--------------------------------------------------------------------------
  138. # ● SPメーター の描画
  139. #--------------------------------------------------------------------------
  140. def draw_actor_sp_meter_line(actor, x, y, width = 156, height = 4)
  141. w = width * actor.sp / [actor.maxsp,1].max
  142. hp_color_1 = Color.new( 0, 0, 255, 192)
  143. hp_color_2 = Color.new( 0, 255, 255, 192)
  144. self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  145. draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  146. x -= 1
  147. y += (height/4).floor
  148. self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  149. draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  150. x -= 1
  151. y += (height/4).ceil
  152. self.contents.fill_rect(x+8, y+4, width, (height/4).ceil , Color.new(0, 0, 0, 128))
  153. draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  154. x -= 1
  155. y += (height/4).ceil
  156. self.contents.fill_rect(x+8, y+4, width, (height/4).floor, Color.new(0, 0, 0, 128))
  157. draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  158. end
  159. #--------------------------------------------------------------------------
  160. # ● 名前の描画
  161. #--------------------------------------------------------------------------
  162. alias xrxs_bp7_draw_actor_name draw_actor_name
  163. def draw_actor_name(actor, x, y)
  164. xrxs_bp7_draw_actor_name(actor, x, y) if @draw_ban != true
  165. end
  166. #--------------------------------------------------------------------------
  167. # ● ステートの描画
  168. #--------------------------------------------------------------------------
  169. alias xrxs_bp7_draw_actor_state draw_actor_state
  170. def draw_actor_state(actor, x, y, width = 120)  
  171. xrxs_bp7_draw_actor_state(actor, x, y, width) if @draw_ban != true
  172. end
  173. #--------------------------------------------------------------------------
  174. # ● HP の描画
  175. #--------------------------------------------------------------------------
  176. alias xrxs_bp7_draw_actor_hp draw_actor_hp
  177. def draw_actor_hp(actor, x, y, width = 144)
  178. xrxs_bp7_draw_actor_hp(actor, x, y, width) if @draw_ban != true
  179. end
  180. #--------------------------------------------------------------------------
  181. # ● SP の描画
  182. #--------------------------------------------------------------------------
  183. alias xrxs_bp7_draw_actor_sp draw_actor_sp
  184. def draw_actor_sp(actor, x, y, width = 144)
  185. xrxs_bp7_draw_actor_sp(actor, x, y, width) if @draw_ban != true
  186. end
  187. end
  188. #==============================================================================
  189. # ■ Scene_Battle
  190. #==============================================================================
  191. class Scene_Battle
  192. #--------------------------------------------------------------------------
  193. # ● フレーム更新
  194. #--------------------------------------------------------------------------
  195. alias xrxs_bp7_update update
  196. def update
  197. xrxs_bp7_update
  198. # メッセージウィンドウ表示中の場合
  199. if $game_temp.message_window_showing
  200. @status_window.update_cp_only = true
  201. else
  202. @status_window.update_cp_only = false
  203. end
  204. end
  205. end
  206. #==============================================================================
  207. # ◇ 外部ライブラリ
  208. #==============================================================================
  209. class Window_Base
  210. #--------------------------------------------------------------------------
  211. # ● ライン描画 軽量版 by 桜雅 在土
  212. #--------------------------------------------------------------------------
  213. def draw_lineght(start_x, start_y, end_x, end_y, start_color)
  214. # 描写距離の計算。大きめに直角時の長さ。
  215. distance = (start_x - end_x).abs + (start_y - end_y).abs
  216. # 描写開始
  217. for i in 1..distance
  218. x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  219. y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  220. self.contents.set_pixel(x, y, start_color)
  221. end
  222. end
  223. #--------------------------------------------------------------------------
  224. # ● ライン描画 by 桜雅 在土
  225. #--------------------------------------------------------------------------
  226. def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
  227. # 描写距離の計算。大きめに直角時の長さ。
  228. distance = (start_x - end_x).abs + (start_y - end_y).abs
  229. # 描写開始
  230. if end_color == start_color
  231. for i in 1..distance
  232. x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  233. y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  234. if width == 1
  235. self.contents.set_pixel(x, y, start_color)
  236. else
  237. self.contents.fill_rect(x, y, width, width, start_color)
  238. end
  239. end
  240. else
  241. for i in 1..distance
  242. x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  243. y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  244. r = start_color.red * (distance-i)/distance + end_color.red * i/distance
  245. g = start_color.green * (distance-i)/distance + end_color.green * i/distance
  246. b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
  247. a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
  248. if width == 1
  249. self.contents.set_pixel(x, y, Color.new(r, g, b, a))
  250. else
  251. self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
  252. end
  253. end
  254. end
  255. end
  256. end

  257. #==============================================================================
  258. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  259. #==============================================================================
复制代码

作者: 恐惧剑刃    时间: 2014-8-3 12:40
错误原因 召唤兽没有头像
def dispose
  super  
  for actor_index in 1..$game_party.actors.size
    next if @sta_back[actor_index].nil?   
    @sta_back[actor_index].bitmap.dispose
    @sta_back[actor_index].dispose
  end
end
作者: gkl0510    时间: 2014-8-3 13:55
恐惧剑刃 发表于 2014-8-3 12:40
错误原因 召唤兽没有头像
def dispose
  super  

帅呆了!
想了一个晚上的问题竟然就被一行代码解决了。

会ruby真幸福啊!
感激涕零!




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