设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1564|回复: 6
打印 上一主题 下一主题

[已经解决] 如何刷新窗口里的状态槽?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
帖子
113
跳转到指定楼层
1
发表于 2012-12-31 20:41:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
刚做了一个在地图上显示状态的窗口,在scene_map里也添加了显示和刷新的判定。现在的问题是,数据变更以后窗口里的数字会自动刷新,但是绘制的几个状态槽就直接消失了。希望大家帮我看看是怎么回事?窗口代码如下:

RUBY 代码复制
  1. class Window_Mapstatus < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化窗口
  4.   #--------------------------------------------------------------------------
  5.     def initialize
  6.       @t = $game_variables[24]
  7.       super(27, 0, 800, 46)
  8.       self.contents = Bitmap.new(width - 32, height - 32)
  9.       self.contents.font.size = 18
  10.       self.contents.font.color = normal_color
  11.       refresh
  12.     end
  13.   #--------------------------------------------------------------------------
  14.   # ● 刷新
  15.   #--------------------------------------------------------------------------
  16.     def refresh
  17.       self.contents.clear
  18.       self.contents.font.color = system_color
  19.       self.contents.font.size = 18
  20.       draw_stamina_bar(x+20,y,110,12)
  21.       draw_hunger_bar(x+220,y,110,12)
  22.       draw_mood_bar(x+420,y,110,12)
  23.       draw_social_bar(x+620,y,110,12)
  24.       self.contents.draw_text(50,-10,110,32, $game_variables[86].to_s)
  25.       self.contents.draw_text(250,-10,110,32, $game_variables[87].to_s)
  26.       self.contents.draw_text(450,-10,110,32, $game_variables[88].to_s)
  27.       self.contents.draw_text(650,-10,110,32, $game_variables[89].to_s)
  28.     end
  29.   #--------------------------------------------------------------------------
  30.   # ● 描绘体力槽
  31.   #--------------------------------------------------------------------------
  32.     def draw_stamina_bar(x, y, width = 110, height = 4)
  33.       stamina = $game_variables[86]
  34.       w = width * stamina / 100
  35.       hp_color_1 = Color.new(255, 195, 195, 192)
  36.       hp_color_2 = Color.new(195, 180, 255, 192)
  37.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  38.       x -= 1
  39.       y += (height/4).floor
  40.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  41.       x -= 1
  42.       y += (height/4).ceil
  43.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  44.       x -= 1
  45.       y += (height/4).ceil
  46.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  47.     end
  48.   #--------------------------------------------------------------------------
  49.   # ● 描绘饱食槽
  50.   #--------------------------------------------------------------------------
  51.     def draw_hunger_bar(x, y, width = 110, height = 4)
  52.       hunger = $game_variables[87]
  53.       w = width * hunger / 100
  54.       hp_color_1 = Color.new(255, 195, 195, 192)
  55.       hp_color_2 = Color.new(195, 180, 255, 192)  
  56.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  57.       x -= 1
  58.       y += (height/4).floor
  59.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  60.       x -= 1
  61.       y += (height/4).ceil
  62.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  63.       x -= 1
  64.       y += (height/4).ceil
  65.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  66.     end
  67.   #--------------------------------------------------------------------------
  68.   # ● 描绘愉悦槽
  69.   #--------------------------------------------------------------------------
  70.     def draw_mood_bar(x, y, width = 110, height = 4)
  71.       mood = $game_variables[88]
  72.       w = width * mood / 100
  73.       hp_color_1 = Color.new(255, 195, 195, 192)
  74.       hp_color_2 = Color.new(195, 180, 255, 192)  
  75.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  76.       x -= 1
  77.       y += (height/4).floor
  78.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  79.       x -= 1
  80.       y += (height/4).ceil
  81.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  82.       x -= 1
  83.       y += (height/4).ceil
  84.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  85.     end
  86.   #--------------------------------------------------------------------------
  87.   # ● 描绘社交槽
  88.   #--------------------------------------------------------------------------
  89.     def draw_social_bar(x, y, width = 110, height = 4)
  90.       social = $game_variables[89]
  91.       w = width * social / 100
  92.       hp_color_1 = Color.new(255, 195, 195, 192)
  93.       hp_color_2 = Color.new(195, 180, 255, 192)  
  94.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  95.       x -= 1
  96.       y += (height/4).floor
  97.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  98.       x -= 1
  99.       y += (height/4).ceil
  100.       draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
  101.       x -= 1
  102.       y += (height/4).ceil
  103.       draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
  104.     end
  105.   end

Lv1.梦旅人

梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
帖子
113
2
 楼主| 发表于 2013-1-1 16:43:55 | 只看该作者
试着把刷新改成连续刷新也不行,为什么draw_text就可以即时刷新而draw_line就不行呢?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
47
在线时间
976 小时
注册时间
2011-4-30
帖子
860
3
发表于 2013-1-1 17:19:09 | 只看该作者
你贴的这段看不出draw_line 是怎么定义的,draw_text能显示证明刷新显示没问题。可能问题出在draw_line
湿滑落式骑!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
帖子
113
4
 楼主| 发表于 2013-1-2 09:56:50 | 只看该作者
羞射了 发表于 2013-1-1 21:19
你贴的这段看不出draw_line 是怎么定义的,draw_text能显示证明刷新显示没问题。可能问题出在draw_line  ...

draw_line的在这里:
RUBY 代码复制
  1. def draw_line(start_x, start_y, end_x, end_y, start_color, width = 1, end_color = start_color)
  2.     # 描写距離の計算。大きめに直角時の長さ。
  3.     distance = (start_x - end_x).abs + (start_y - end_y).abs
  4.     # 描写開始
  5.     if end_color == start_color
  6.       for i in 1..distance
  7.         x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  8.         y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  9.         if width == 1
  10.           self.contents.set_pixel(x, y, start_color)
  11.         else
  12.           self.contents.fill_rect(x, y, width, width, start_color)
  13.         end
  14.       end
  15.     else
  16.       for i in 1..distance
  17.         x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
  18.         y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
  19.         r = start_color.red * (distance-i)/distance + end_color.red * i/distance
  20.         g = start_color.green * (distance-i)/distance + end_color.green * i/distance
  21.         b = start_color.blue * (distance-i)/distance + end_color.blue * i/distance
  22.         a = start_color.alpha * (distance-i)/distance + end_color.alpha * i/distance
  23.         if width == 1
  24.           self.contents.set_pixel(x, y, Color.new(r, g, b, a))
  25.         else
  26.           self.contents.fill_rect(x, y, width, width, Color.new(r, g, b, a))
  27.         end
  28.       end
  29.     end
  30.   end
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
47
在线时间
976 小时
注册时间
2011-4-30
帖子
860
5
发表于 2013-1-2 11:45:28 | 只看该作者
哦,我略微看了下,问题可能还是出在第一篇里,
举个例子,我觉得以下的写法都可能会产生问题,比如:
draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)
      x -= 1
      y += (height/4).floor
      draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
      x -= 1
      y += (height/4).ceil
      draw_line(x, y, x + w, y, hp_color_1, (height/4).ceil , hp_color_2)
      x -= 1
      y += (height/4).ceil
      draw_line(x, y, x + w, y, hp_color_1, (height/4).floor, hp_color_2)

不知道你是自己摸索的还是谁把你教坏了……

,因为你把drawline贴出来了,我试着重现了一下效果,我个人建议可以改成
      for i in 0...height
        draw_line(x-i+height, y+i, x-i+height+w, y+i, hp_color_1, 1, hp_color_2)
      end
这样就ok
湿滑落式骑!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
381 小时
注册时间
2012-8-13
帖子
113
6
 楼主| 发表于 2013-1-2 18:44:45 | 只看该作者
羞射了 发表于 2013-1-2 15:45
哦,我略微看了下,问题可能还是出在第一篇里,
举个例子,我觉得以下的写法都可能会产生问题,比如:
draw ...

多谢你的回答。我试了你说的方法,不过改完以后状态槽还是一刷新就消失。我发现切换到主菜单再切回地图就可以正常显示刷新后的状态槽了。我试了论坛里找的另外一个状态槽,还是同样的情况,所以我感觉应该跟状态槽这种显示方式有关?但是同样的状态槽在战斗场景下就工作正常。这是怎么回事呢?

附上另一个状态槽的代码:
RUBY 代码复制
  1. # -----------------------------------------------------------------------------
  2. # 值槽脚本随机生成系统(SLOTCR) By.Clov
  3. # 通用版本:RMXP(RGSS1) RMVX(RGSS2) RMVX ACE(RGSS3)
  4. # 使用方法:在全部窗口类插入即可 例:draw_cr(0,0,变量1,变量2,'开心值',100,10)
  5. # 参数说明:x x坐标,y y坐标,current 当前值,max 最大值,txt 显示的文字
  6. # width 值槽的宽,height 值槽的高
  7. # 背景与边框没有随机的必要,请自行到脚本里设置
  8. # -----------------------------------------------------------------------------
  9. class Window_Base
  10.    def draw_cr(x,y,current,max,txt='',width=128,height=15)
  11.     #颜色1、颜色2
  12.     c1=[59, 191, 119];c2=[253, 94, 1]
  13.     #边框色颜色
  14.     bk_color = Color.new(255,255,255,255)
  15.     #数值是否显示
  16.     num = true
  17.     #显示数值的对齐方式 0:向左对齐 1:向中间对齐 2:向右边对齐
  18.     num_align = 1
  19.     #计算比率
  20.     bl = current.to_f / max
  21.     #计算实际宽
  22.     w = (width*bl).round
  23.     #描绘值槽
  24.     r = c1[0];g = c1[1];b = c1[2]
  25.     plus_r = (c2[0]-c1[0])/((width-1)*bl)
  26.     plus_g = (c2[1]-c1[1])/((width-1)*bl)
  27.     plus_b = (c2[2]-c1[2])/((width-1)*bl)
  28.     w.times {|k|
  29.     contents.fill_rect(x+k, y, 1, height, Color.new(r,g,b,255))
  30.     r+=plus_r;g+=plus_g;b+=plus_b}
  31.     contents.fill_rect(x-1, y-1, width+2, 1, bk_color)
  32.     contents.fill_rect(x-1, y+height, width+2, 1, bk_color)
  33.     contents.fill_rect(x-1, y, 1, height, bk_color)
  34.     contents.fill_rect(x+width, y, 1, height, bk_color)
  35.     #描绘文字
  36.     txt_w = contents.text_size(txt).width + 2
  37.     contents.draw_text(x-txt_w,y+height/2-12, width, 24, txt)
  38.     contents.draw_text(x,y+height/2-12, width, 24,
  39.     current.to_s+'/'+max.to_s,num_align) if num
  40.   end
  41. end

点评

战斗系统用的是RTAB,刷新状态槽一切正常  发表于 2013-1-2 18:50
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
47
在线时间
976 小时
注册时间
2011-4-30
帖子
860
7
发表于 2013-1-2 19:09:21 | 只看该作者
tyq4590 发表于 2013-1-2 18:44
多谢你的回答。我试了你说的方法,不过改完以后状态槽还是一刷新就消失。我发现切换到主菜单再切回地图就 ...

那就可能是你scene_map调用的地方有问题了。
湿滑落式骑!
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-27 20:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表