查看: 2518|回复: 3

[已经解决] 经验条显示异常

[复制链接]
梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
发表于 2022-5-12 23:14:35 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
在脚本里加入了一个经验条显示的功能,但是发现关闭窗口的时候,经验条还会显示在地图上,等几秒才消失,不知道啥情况。。。


1.png



如图BUG
2.png

  1. #==============================================================================
  2. # ■ JD_DL
  3. #------------------------------------------------------------------------------
  4. #  显示加点状态窗口。
  5. #==============================================================================

  6. class JD_DL < Window_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     actor : 角色
  10.   #--------------------------------------------------------------------------
  11.   def initialize(actor)
  12.     super(160+300, 100, 480, 320)
  13.     self.contents = Bitmap.new(width - 32, height - 32)
  14.     self.contents.font.size = 16
  15.     @actor = actor
  16.     # 文字高
  17.     # 可以放在refresh里 实时控制
  18.     @sh = 32
  19.     refresh
  20.   end  
  21.   #--------------------------------------------------------------------------
  22.   # ● 刷新
  23.   #--------------------------------------------------------------------------
  24.   def refresh
  25.     self.contents.clear
  26.     draw_actor_face(@actor, 0, 0)         # 头像
  27.     draw_actor_name_duiwu(@actor, 20, 0)  # 名字
  28.     draw_actor_level(@actor, 20, 32)      # 等级
  29.     draw_v(0, 32*2, 0)                    # 气血
  30.     draw_v(0, 32*3, 1)                    # 法力
  31.     draw_dl(0, 32*4, 0)                   # 力量
  32.     draw_dl(0, 32*5, 1)                   # 魔力
  33.     draw_dl(0, 32*6, 2)                   # 速度
  34.     draw_dl(0, 32*7, 3)                   # 灵巧
  35.     # 潜力描绘
  36.     self.contents.font.color = system_color
  37.     str = "潜力"
  38.     self.contents.draw_text(0, 32*8, sw(str), @sh, str) # 潜力
  39.     cx = sw(str)
  40.     # ** 调整颜色
  41.     if $point != @actor.qianli
  42.       self.contents.font.color = text_color(6)
  43.     else
  44.       self.contents.font.color = normal_color
  45.     end
  46.     # 潜力数值描绘
  47.     self.contents.draw_text(cx + 10, 32*8, sw($point.to_s), @sh, $point.to_s) #数值
  48.     # 描绘经验条
  49.     self.contents.font.color = normal_color
  50.     self.contents.draw_text(100, 235, 300, 32, @actor.exp_s + "/" + @actor.next_exp_s)
  51.     #--------经验条显示------------------------------------------------------  
  52.     @exp_a = nil
  53.     @exp_b = nil   
  54.     @exp_a = Sprite.new
  55.     @exp_b = Sprite.new  
  56.     #--------经验条窗口显示--------------------------------------------------
  57.     @exp_a.bitmap = Bitmap.new(168,10)     #(经验条1宽度,第高度)
  58.     @exp_b.bitmap = Bitmap.new(168,5)      #(经验条2宽度,第高度)
  59.     #--------经验条颜色------------------------------------------------------
  60.     color1 = Color.new(111,172,115,255)  #经验条1颜色
  61.     color2 = Color.new(49,159,51,255)    #经验条2颜色
  62.     #--------经验值增幅度----------------------------------------------------
  63.     next_exp = @actor.next_exp_s.to_i == 0 ? @actor.exp : @actor.next_exp_s.to_i
  64.     @exp_d = 168*@actor.exp/next_exp
  65.     #--------经验条增幅条1---------------------------------------------------
  66.     @exp_a.x = 576
  67.     @exp_a.y = 380
  68.     @exp_a.z = 1000
  69.     @exp_a.bitmap.fill_rect(0,0,@exp_d,32,color1)
  70.     #--------经验条增幅条2---------------------------------------------------
  71.     @exp_b.x = 576
  72.     @exp_b.y = 383
  73.     @exp_b.z = 1000
  74.     @exp_b.bitmap.fill_rect(0,0,@exp_d,32,color2)
  75.     end
  76.     #--------释放经验条------------------------------------------------------
  77.     def dispose
  78.     super   
  79.     @exp_a.bitmap.dispose  
  80.     @exp_b.bitmap.dispose  
  81.     @exp_a.dispose   
  82.     @exp_b.dispose
  83.     @exp_a = nil
  84.     @exp_b = nil  
  85.     #------------------------------------------------------------------------   
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   #  **  属性描绘
  89.   #--------------------------------------------------------------------------
  90.   # ** 返回字符串的宽度
  91.   def sw(s)
  92.     return self.contents.text_size(s).width
  93.   end
  94.   # ** HP AND SP 描绘
  95.   def draw_v(x, y, type)
  96.     case type
  97.     when 0
  98.       word = $data_system.words.hp
  99.       dl = @actor.hp
  100.       max = @actor.maxhp
  101.       temp = $temp_hp
  102.     when 1
  103.       word = $data_system.words.sp
  104.       dl = @actor.sp
  105.       max = @actor.maxsp
  106.       temp = $temp_sp
  107.     else
  108.       return
  109.     end
  110.     self.contents.font.color = system_color
  111.     # ** 用语
  112.     str = word
  113.     self.contents.draw_text(x, y, sw(str), @sh, str)
  114.     self.contents.font.color = normal_color
  115.     # ** 基本值
  116.     cx = sw(str)
  117.     str = dl.to_s + "/"
  118.     self.contents.draw_text(x + cx + 10, y, sw(str), @sh, str)
  119.     cx += sw(str)
  120.     # ** 调整颜色
  121.     if temp > 0
  122.       self.contents.font.color = text_color(6)
  123.     else
  124.       self.contents.font.color = normal_color
  125.     end
  126.     # ** 基本值 max
  127.     str = (max + temp).to_s
  128.     self.contents.draw_text(x + cx + 10, y, sw(str), @sh, str)
  129.     cx += sw(str)
  130.     # ** 附加值
  131.     if temp > 0
  132.       self.contents.font.color.set(255, 100, 100)
  133.       str = "(+" + temp.to_s + ")"
  134.       self.contents.draw_text(x + cx + 10, y, sw(str), @sh, str)
  135.     end
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   #  **  属性描绘
  139.   #--------------------------------------------------------------------------
  140.   def draw_dl(x, y, type)
  141.     # ** 准备描绘
  142.     case type
  143.     when 0
  144.       word = $data_system.words.str
  145.       dl = @actor.str
  146.       plus = $temp_str
  147.     when 1
  148.       word = $data_system.words.int
  149.       dl = @actor.int
  150.       plus = $temp_int
  151.     when 2
  152.       word = $data_system.words.agi
  153.       dl = @actor.agi
  154.       plus = $temp_agi
  155.     when 3
  156.       word = $data_system.words.dex
  157.       dl = @actor.dex
  158.       plus = $temp_dex
  159.     else
  160.       return
  161.     end
  162.     # ** 开始描绘
  163.     self.contents.font.color = system_color
  164.     # ** 用语
  165.     str = word
  166.     self.contents.draw_text(x, y, sw(str), @sh, str)
  167.     # ** 设置新值颜色
  168.     if plus > 0
  169.       self.contents.font.color = text_color(6)
  170.     else
  171.       self.contents.font.color = normal_color
  172.     end
  173.     # ** 基本值
  174.     cx = sw(str)
  175.     str = (dl + plus).to_s
  176.     self.contents.draw_text(x + cx + 10, y, sw(str), @sh, str)
  177.     cx += sw(str)
  178.     # ** 附加值
  179.     if plus > 0
  180.       self.contents.font.color.set(255, 100, 100)
  181.       str = "(+" + plus.to_s + ")"
  182.       self.contents.draw_text(x + cx + 10, y, sw(str), @sh, str)
  183.     end
  184.   end
  185. end
复制代码
梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2022-5-13 00:46:18 | 显示全部楼层
看上去脚本没有问题,可能是你调用的时候忘记了主动 dispose。
你找一下自己写@x = JD_DL.new之后是不是忘了写@x.dispose
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
0
星屑
6483
在线时间
119 小时
注册时间
2020-1-8
回帖
205
发表于 2022-5-13 07:21:18 | 显示全部楼层
你的经验条可以直接描绘在self.contents上,当然用精灵可以避免重复描绘

refresh里重新生成经验条精灵及其位图...,多次调用refresh的话原先生成精灵及其位图并没有释放。
用精灵的话,建议在intialize里生成,并用个实例变量记录具体数据,数据不同的话,再在refresh里对其位图进行重绘等

评分

参与人数 1星屑 +50 收起 理由
RyanBern + 50 认可答案

查看全部评分

回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2022-5-13 14:12:43 | 显示全部楼层
本帖最后由 guoxiaomi 于 2022-5-13 14:13 编辑
RPGzh500223 发表于 2022-5-13 07:21
你的经验条可以直接描绘在self.contents上,当然用精灵可以避免重复描绘

refresh里重新生成经验条精灵及其 ...


原来如此,那他只要在53行前面加上
  1. @exp_a.dispose if @exp_a
  2. @exp_b.dispose if @exp_b
  3. @exp_a = nil
  4. @exp_b = nil
复制代码

评分

参与人数 1星屑 +50 收起 理由
RyanBern + 50 我很赞同

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部