Project1

标题: 如何让窗口更新…… [打印本页]

作者: xggzga117    时间: 2014-3-2 20:50
标题: 如何让窗口更新……
新建了一个在地图上直接显示状态的窗口……
但是它的内容一直是不变的……怎么更新?
作者: tan12345    时间: 2014-3-2 21:09
def update
    super
    xxxx(你的代码)
end
作者: xggzga117    时间: 2014-3-2 21:17
我像这样加进去……
  #--------------------------------------------------------------------------
  # ● 更新画面
  #--------------------------------------------------------------------------
  def update
    super
    draw_shit1
  end
但是画面变成很多个重在一起,而且游戏变得很卡……怎么解决?
作者: やなちゃん    时间: 2014-3-2 21:44
搜尋可以找到你想要的做參考

by余烬之中
http://rpg.blue/forum.php?mod=viewthread&tid=338051

by芙蕾娅
http://rpg.blue/home.php?mod=spa ... o=blog&id=11428

by喵呜喵5
http://rpg.blue/home.php?mod=spa ... o=blog&id=12023
作者: 喵呜喵5    时间: 2014-3-2 21:51
def update
super
draw_shit1 if 窗口的内容改变了
end
作者: sh0016    时间: 2014-3-5 04:13
Scene里面插这段?
  1. def update
  2.   super
  3.   @xxx(窗口名).refresh
  4. end
复制代码

作者: taroxd    时间: 2014-3-5 09:39
(RGSS3)场景会自动更新其所有窗口实例变量,无需手动调用
作者: xggzga117    时间: 2014-3-8 20:15
  def
  refresh
  if $game_variables[2] == true
    draw_shit1
    $game_switches[2] = false
  end
这样可以么?
作者: SuperMario    时间: 2014-3-9 01:01
本帖最后由 Sion 于 2014-3-9 16:20 编辑

先clear再draw。
作者: 影月千秋    时间: 2014-3-9 12:10
  1. def update
  2.   super
  3.   refresh if need_refresh?
  4. end

  5. def refresh
  6.   contents.clear
  7.   # 进行绘制操作
  8. end

  9. def need_refresh?
  10.   # 判断什么情况下需要重新绘制
  11.   # 例
  12.   # $game_variables[2] == true
  13. end
复制代码

作者: xggzga117    时间: 2014-3-9 14:27
本帖最后由 xggzga117 于 2014-3-9 14:29 编辑

嗯成功了!把相关脚本发上来……
  #--------------------------------------------------------------------------
  # ● 更新画面
  #--------------------------------------------------------------------------
  def update
    contents.clear if $game_switches[2] == true
    draw_shit1 if $game_switches[2] == true
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    draw_shit1
  end
……顺手把我自己做的东西也传上来吧。(PS.11号角色的名字就是斜杠)
  #--------------------------------------------------------------------------
  # ● 生成窗口内容
  #--------------------------------------------------------------------------
  def draw_shit1
    draw_text(0, 0, 640, 24, $game_map.display_name)
    draw_text(0, 24, 640, 24, $game_actors[12].name)
    draw_text(64, 24, 640, 24, Vocab::hp_a)
    draw_text(96, 24, 640, 24, $game_actors[12].hp)
    draw_text(136, 24, 640, 24, $game_actors[11].name)
    draw_text(160, 24, 640, 24, $game_actors[12].mhp)
    draw_text(240, 24, 640, 24, Vocab::mp_a)
    draw_text(272, 24, 640, 24, $game_actors[12].mp)
    draw_text(312, 24, 640, 24, $game_actors[11].name)
    draw_text(336, 24, 640, 24, $game_actors[12].mmp)
  end
end
作者: 影月千秋    时间: 2014-3-9 16:12
本帖最后由 影月千秋 于 2014-3-9 16:13 编辑
xggzga117 发表于 2014-3-9 14:27
嗯成功了!把相关脚本发上来……
  #------------------------------------------------------------------ ...


楼主你发现没有,三个方法update refresh draw_shit1 他们的调用关系是这样的:


右上角那个蓝色的块是 contents

没有一个方法调用refresh 也就是说 那是一个完全没有用处的方法

怎么会这样呢?

分析一下我们的本意  应该是这样的吧:

外部 => update => refresh => draw_shit1

所以 应该把update调整一下
RUBY 代码复制
  1. def update
  2.   contents.clear if $game_switches[2] == true
  3.   refresh if $game_switches[2] == true
  4. end



另外 如果只有一个语句,使用if修饰符很简洁,比如 do if need_to_do

但是 需要执行两个语句时 还是合并在一起吧

把update再微调:
RUBY 代码复制
  1. def update
  2.   if $game_switches[2] == true
  3.     contents.clear
  4.     refresh
  5.   end
  6. end



这样是推荐的一般写法

当然 还有两种写法 比较灵活
其一其二
因为整个update方法只有一个判定:如果满足 执行 不满足 什么也不做
我们可以让这个更直观
如果不满足 什么也不做
这算是比较取巧的做法 不推荐使用 但值得了解
本质是构建数组时进行的求值
RUBY 代码复制
  1. def update
  2.   return if $game_switches[2] != true
  3.   contents.clear
  4.   refresh
  5. end
RUBY 代码复制
  1. def update
  2.   [contents.clear, refresh] if $game_switches[2] == true
  3. end



=======================================
还有什么没有说?

我推荐把contents.clear放进refresh里 因为那也是重绘的一部分
整体就是这样
RUBY 代码复制
  1. def update
  2.   draw_shit1 if $game_switches[2]
  3. end
  4. def refresh
  5.   contents.clear
  6.   draw_shit1
  7. end
  8. # def contents.clear省略


注意到了draw_shit1 if $game_switches[2]吗?
在这里,它和draw_shit1 if $game_switches[2] == true是等价的
但本质上有一点微妙的区别
但是 对于保存真伪值(true false)的变量  影响不是很大  一般都能混用




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