Project1

标题: 请问这个脚本◆显示文章怎么使用。。尴尬 [打印本页]

作者: j296196585    时间: 2016-12-3 12:23
标题: 请问这个脚本◆显示文章怎么使用。。尴尬
[pre lang="ruby"]#使用手冊!
#在Main 裏的14行增加 Mess_Text.ini
#
#==============================================================================
# ■ module Mess_Text
#------------------------------------------------------------------------------
#  在地图上显示文章的模块。
#==============================================================================
module Mess_Text
  MAX_LINE = 5  # 最大的行数
  MAX_TIME = 210 # 文字的维持时间
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def self.ini
    @text_sprite = Sprite.new
    @text_sprite.bitmap = Bitmap.new(350,290)
    @text_sprite.x = 10
    @text_sprite.y = 236 + 124
    @text_sprite.z = 100
    @line = 0
    @Time = MAX_TIME
  end
  #--------------------------------------------------------------------------
  # ● 设置可见度
  #--------------------------------------------------------------------------
  def self.visible=(v)
    @text_sprite.visible = v
  end
  #--------------------------------------------------------------------------
  # ● 获取可见度
  #--------------------------------------------------------------------------
  def self.visible
    return @text_sprite.disposed? ? false : @text_sprite.visible
  end
  #--------------------------------------------------------------------------
  # ● 释放
  #--------------------------------------------------------------------------
  def self.dispose
    @text_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # ● 清空
  #--------------------------------------------------------------------------
  def self.clear
    @text_sprite.bitmap.clear
    @line = 0
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def self.update
    if @time > 0
      @time -= 1
    end
    if @time <= 0
      @text_sprite.bitmap.clear
      @line = 0
    end
  end
  
  def self.write(str)
    if @line >= MAX_LINE
      @text_sprite.bitmap.clear
      @line = 0
    end
    @text_sprite.bitmap.font.size = 16
    text_color(2)
    cw = @text_sprite.bitmap.text_size(str).width
    @text_sprite.bitmap.draw_text(0, @line * @text_sprite.bitmap.font.size, cw, 20, str)
    @line += 1
    @time = MAX_TIME
  end
  #--------------------------------------------------------------------------
  # ● 获取文字色
  #     n : 文字色编号 (0~7)
  #--------------------------------------------------------------------------
  def self.text_color(n)
    case n
    when 0
      return Color.new(255, 255, 255, 255)
    when 1
      return Color.new(128, 128, 255, 255)
    when 2
      return Color.new(255, 128, 128, 255)
    when 3
      return Color.new(128, 255, 128, 255)
    when 4
      return Color.new(128, 255, 255, 255)
    when 5
      return Color.new(255, 128, 255, 255)
    when 6
      return Color.new(255, 255, 128, 255)
    when 7
      return Color.new(192, 192, 192, 255)
    else
      normal_color
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取普通文字色
  #--------------------------------------------------------------------------
  def self.normal_color
    return Color.new(255, 255, 255, 255)
  end
end[/pre]
作者: cinderelmini    时间: 2016-12-3 13:50
本帖最后由 cinderelmini 于 2016-12-3 13:54 编辑

唔、、除了代码框第二行说的在Main放个 Mess_Text.ini 之外,
大概还需要在Scene_Base的update里面再加一行
  1. Mess_Text.update
复制代码
然后在想要绘制文字的时候:
  1. Mess_Text.write("文本行1")
  2. Mess_Text.write("文本行2")
  3. Mess_Text.write("文本行3")
  4. ...
复制代码
这样执行。
PS:显示之后的文本会淡出但文本记录不会自己消除,下次调用 Mess_Text.write 的时候会往下一行加,
如果要清除之前显示的内容的话,在显示之前使用 Mess_Text.clear 清除一下记录。
PPAP:代码框21行和22行的格式→_→。。




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