Project1

标题: 让窗口逐渐出现/消失的问题 [打印本页]

作者: 离小可    时间: 2013-5-12 12:51
标题: 让窗口逐渐出现/消失的问题
本帖最后由 Sion 于 2013-5-25 17:18 编辑

我在地图界面中直接用Window_Base构建了一个窗口来显示我想输入的东西~
比如这样 (游戏用的分辨率是800*600)
$test = Window_Base.new(20, 20, 800, 48)
$test.contents.draw_text(0, 0, 800, 30, "测试", 0)

然后我觉得直接这样显示很突兀,就加了一个让他逐渐出现的方法
$test.opacity = 0
$test.contents_opacity = 0
for i in 0..30
  Graphics.update
  $test.opacity += 255/30
  $test.contents_opacity += 255/30
end

但是这样一来就出现问题了,
如果我需要窗口出现的时间特别长,比如300帧(上面那个是30帧),
那在窗口显示的30帧内,人物就什么都不能做
我尝试过在事件里面用并行处理调用过那个界面,也不行的
请问~怎样在让窗口逐渐显示的同时 又能控制人物呢?

(我也试过把Graphics.update删掉,但是这样一来就没法精确控制时间——因为i递加得太快~)

小白真心求解
作者: 沙漠点灰    时间: 2013-5-12 13:13
脚本里找个位置,最好就是第一个
RUBY 代码复制
  1. module Math
  2.   def self.f(x)
  3.     return self.f(x+1) if x < 0
  4.     return self.f(x-1) if x > 2
  5.     (x-1)**2
  6.   end
  7. end
  8. class Window_Base
  9.   #--------------------------------------------------------------------------
  10.   # ● 移动到
  11.   #--------------------------------------------------------------------------
  12.   def move_to(x, y,duration, opa=nil)
  13.     @old_x = self.x
  14.     @old_y = self.y
  15.     @target_x = (x ? x : self.x)
  16.     @target_y = (y ? y : self.y)
  17.     @target_opa = (opa ? opa : @target_opa)
  18.     @old_opa = self.opacity
  19.     @duration = duration
  20.     @duration_full = duration.to_f
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 刷新移动
  24.   #--------------------------------------------------------------------------
  25.   def move_update
  26.     return true if @duration.nil? or @duration <= 0
  27.     @duration -= 1
  28.     var = 1-Math.f(@duration/@duration_full+1)
  29.     self.x = (@old_x + (@target_x-@old_x) *var+0.5).to_i
  30.     self.y = (@old_y + (@target_y-@old_y) *var+0.5).to_i
  31.     self.opacity = @old_opa + (@target_opa - @old_opa)*var if @target_opa
  32.     self.contents_opacity = self.opacity
  33.     false
  34.   end
  35. end

找到Scene_Map的update方法,里面加一句update_diy_windows
再在main前加上:
RUBY 代码复制
  1. class Scene_Map
  2.   def update_diy_windows
  3.     @diy_windows ||= []
  4.     @diy_windows.each{|wnd|wnd.move_update;wnd.update}
  5.   end
  6.   def add_diy_window(wnd)
  7.     @diy_windows ||= []
  8.     @diy_windows << wnd
  9.   end
  10.   def dispose_diy_window(wnd)
  11.     @diy_windows ||= []
  12.     @diy_windows.delete(wnd)
  13.     wnd.dispose
  14.   end
  15. end



使用方法,如lz写得那样,但是本脚本只在地图上有效,其他地方(如战斗时)使用会出错.
$test = Window_Base.new(20, 20, 800, 48)
$test.contents.draw_text(0, 0, 800, 30, "测试", 0)
SceneManager.scene.add_diy_window($test)
$test.opacity = 0
$test.contents_opacity = 0
$test.move_to(nil, nil, 300, 255)


就能在300内将窗口从透明变为不透明。

$test.move_to(500, 20, 30, 255)

就能在300内将窗口从原位置移动到(500, 20)透明变为不透明。
$test.move_to(500, nil, 30, 255)
$test.move_to(nil, 500, 30, 255)
这个lz可以试试

释放窗口使用:
SceneManager.scene.dispose_diy_window($test)
就行,没试过,可能有错
作者: j433463    时间: 2013-5-12 13:15
不要用 for 跑回圈,那得等回圈跑完才会执行后面的,您应该在 def update 刷新那边做,

并且用一个变量来计算执行次数,譬如 ot += 1,判断 ot 小于 30 就执行原本在 for 内的代码。




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