Project1

标题: 窗口隐藏失效 [打印本页]

作者: 黑米馒头    时间: 2022-11-6 13:12
标题: 窗口隐藏失效
本帖最后由 黑米馒头 于 2022-11-6 18:37 编辑

弄了显示敌方剩余战斗力的脚本,想在游戏结束的时候,让窗口隐藏了

首先生成窗口
@zanli = Window_BattleStatus.new

接着在Scene_Battle 1里

    # 游戏结束的情况下
    if $game_temp.gameover

      # 隐藏敌方剩余战力窗口
      @zanli.nrxc

      # 切换到游戏结束画面
      $scene = Scene_Gameover.new
      return
    end

但是会出现很奇怪的问题,有时候游戏结束窗口会隐藏,有时候又不会隐藏

战斗时显示


游戏结束的时候

未隐藏


隐藏




RUBY 代码复制
  1. #------------------------------------------------------------------------------
  2. # 显示敌方剩余战斗力
  3. #==============================================================================
  4. #--------------------------------------------------------------------------
  5. # □ 常数设置
  6. #--------------------------------------------------------------------------
  7. module ZENITH4
  8.   EG_WIDTH = 165+100    # 长度
  9.   EG_COLOR = Color.new(255,0,0,255) #(255, 180, 0, 255)   # 战力颜色(黄色)
  10.   EW_NAME = "敌方剩余生命"
  11.   EW_COLOR = Color.new(255, 255, 255, 255) # 文字颜色
  12. end
  13.  
  14. #==============================================================================
  15. # ■ Window_BattleStatus
  16. #==============================================================================
  17. class Window_BattleStatus < Window_Base
  18. #--------------------------------------------------------------------------
  19. # ● 对象初始化
  20. #--------------------------------------------------------------------------
  21. alias zenith4_initialize initialize
  22. def initialize
  23.   @enemy_force = Sprite.new
  24.   @enemy_force.bitmap = Bitmap.new(8 + ZENITH4::EG_WIDTH+100, 45)
  25.   @enemy_force.x = 185 - (12 + ZENITH4::EG_WIDTH)+200
  26.   @enemy_force.y = 6#115
  27.   @enemy_force.z = 250
  28.   @nrbj = true
  29.   zenith4_initialize
  30. end
  31. #--------------------------------------------------------------------------
  32. # ● 解放
  33. #--------------------------------------------------------------------------
  34. alias zenith4_dispose dispose
  35. def dispose
  36.   zenith4_dispose
  37. end
  38. #--------------------------------------------------------------------------
  39. # ● 刷新
  40. #--------------------------------------------------------------------------
  41. alias zenith4_refresh refresh
  42. def refresh
  43.   zenith4_refresh
  44.   if @nrbj
  45.     @enemy_force.visible = true
  46.     @enemy_force.bitmap.clear
  47.     x = 4
  48.     y = 4
  49.     width = ZENITH4::EG_WIDTH
  50.     @enemy_force.bitmap.font.size = 18
  51.  
  52.     # 描绘字体样式
  53.     @enemy_force.bitmap.font.name = (["黑体"])
  54.  
  55.     @enemy_force.bitmap.font.color = Color.new(0, 0, 0, 255)
  56.     # 描绘文字黑底
  57.     @enemy_force.bitmap.draw_text(x+1+3+24+50+100, y+1, width, 22, ZENITH4::EW_NAME)
  58.     @enemy_force.bitmap.draw_text(x-1+3+24+50+100, y-1, width, 22, ZENITH4::EW_NAME)
  59.     @enemy_force.bitmap.draw_text(x+1+3+24+50+100, y-1, width, 22, ZENITH4::EW_NAME)
  60.     @enemy_force.bitmap.draw_text(x-1+3+24+50+100, y+1, width, 22, ZENITH4::EW_NAME)
  61.     @enemy_force.bitmap.font.color = ZENITH4::EW_COLOR
  62.     # 描绘文字
  63.     @enemy_force.bitmap.draw_text(x+3+24+50+100, y, width, 22, ZENITH4::EW_NAME)
  64.     @item_max = $game_troop.enemies.size
  65.     enemy_mh = 0
  66.     enemy_h = 0
  67.     for i in 0...@item_max
  68.      enemy = $game_troop.enemies[i]
  69.      next if enemy.hidden
  70.      enemy_mh += enemy.maxhp
  71.      enemy_h += enemy.hp
  72.     end
  73.      # 底部描绘
  74.      @enemy_force.bitmap.fill_rect(x-2+100, y+24, width+2,1, Color.new(152, 160, 88, 255))  
  75.      @enemy_force.bitmap.fill_rect(x-1+100, y+26, width,3, Color.new(149,149,149,255))
  76.      @enemy_force.bitmap.fill_rect(x-2+100, y+30, width+2,1, Color.new(152, 160, 88, 255))
  77.      @enemy_force.bitmap.fill_rect(x-3+100, y+24, 1,7, Color.new(152, 160, 88, 255))
  78.      @enemy_force.bitmap.fill_rect(x+165+100+100, y+24, 1,7, Color.new(152, 160, 88, 255))
  79.  
  80.      w = width * enemy_h / enemy_mh
  81.      # 战力描绘
  82.      @enemy_force.bitmap.fill_rect(x-1+100, y+26, w,3, ZENITH4::EG_COLOR)
  83.    end
  84. end
  85.   def nrxc
  86.     @nrbj = false
  87.     @enemy_force.bitmap.dispose
  88.     @enemy_force.dispose
  89.   end
  90. end

作者: RPGzh500223    时间: 2022-11-6 15:59
我没记错的话,你一开始就窗口里面用精灵……
看代码只是控制了@enemy_force这个精灵,并没有控制该窗口
比如隐藏窗口加上 self.visible = false
作者: 黑米馒头    时间: 2022-11-6 16:44
RPGzh500223 发表于 2022-11-6 15:59
我没记错的话,你一开始就窗口里面用精灵……
看代码只是控制了@enemy_force这个精灵,并没有控制该窗口
比 ...

  def nrxc
    @nrbj = false
    self.visible = false
    @enemy_force.bitmap.dispose
    @enemy_force.dispose
  end
是加这块吗,效果还是一样呀
作者: RPGzh500223    时间: 2022-11-6 18:38
RMXP原本有个 Window_BattleStatus 是描绘队员的,你这样重新定义
Scene_Battle的 @status_window 也会有个@enemy_force精灵的
你重新定义个类吧




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