查看: 3272|回复: 2

[已经解决] 小段代码书写请教

[复制链接]
梦石
0
星屑
50
在线时间
13 小时
注册时间
2014-11-12
回帖
38
发表于 2014-11-21 16:20:01 | 显示全部楼层 |阅读模式

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

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

×
我想创建一个窗口
显示位置是屏幕中央 高度为100
文字内容为自定义 脚本里是输入$tip="";$tip_imformation="";
也就是在事件编辑中输入脚本进行调用 但是每次调用3秒之后让窗口消失不太会

[pre lang="ruby" line="1"]
class Window_Tip < Window_Base
  def initialize
    if $tip_information.is_a?(String) and $tip_information!=""
      @temptext = $tip_information.gsub(/(\r\n)|\n/,"")
      i = 1
      p = 0
      insert_list = []
      while p+i<= @temptext.size
        w = tb.text_size(@temptext[p,i]).width
        if w > window_width
          insert_list << p+i-2
          p = p+i-2
          i = 1
        end
        i+=1
      end
      insert_list.reverse!
      insert_list.each{|k| @temptext.insert(k,"\n")}
      tb.dispose
      addheight = (insert_list.size+2) * 24
    end
    super(0,416/2+50, window_width, window_height)
    refresh
  end
  def window_width
    return 544
  end

  def window_height
    return 100
  end
  def refresh
    contents.clear
    if $tip.nil? or $tip==""
      $tip=""
      $tip_information=""
    end
    draw_text_ex(0,0,"\\c[1]#{$tip}")
    text_color(2)
    draw_text_ex(0,24,@temptext)
  end
  def tip
    $tip
  end
  def open
    refresh
    super
  end
end
[/pre]

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-11-21 16:57:26 | 显示全部楼层
窗口有一个 update 方法,通常会每帧调用一次。

在窗口的 update 中,监控 $tip 的变化。

例:
[pre lang="ruby" line="1"]
class Window_XXX

  def update
    refresh unless @tip.equal? $tip
    disappear if Graphics.frame_count - @frame > 180
  end

  def refresh
    @tip = $tip
    @frame = Graphics.frame_count
    # redraw the contents
  end

  def disappear
    # ...
  end

end[/pre]
回复

使用道具 举报

路路 该用户已被删除
发表于 2014-11-21 18:41:23 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部