| 
 
| 赞 | 2 |  
| VIP | 0 |  
| 好人卡 | 0 |  
| 积分 | 20 |  
| 经验 | 0 |  
| 最后登录 | 2021-6-24 |  
| 在线时间 | 410 小时 |  
 Lv3.寻梦者 
	梦石0 星屑1957 在线时间410 小时注册时间2018-9-25帖子38 | 
| 
脚本小白,想请教一下这个立绘脚本要怎么用,是在事件—脚本里面写吗?但是这样就会报错啊
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员   ,有人能说一下要怎么来用吗 
 
 
 复制代码# =============================================================================
=begin
  -----------------------------------------------------------------------------
  *) 介绍:
  -----------------------------------------------------------------------------
  本脚本可以简单地在对话中显示动态立绘
  
  -----------------------------------------------------------------------------
  *) 使用方法 :
  -----------------------------------------------------------------------------
  本脚本放在插件脚本之下,main之上
  
  准备两张任意尺寸的图片。一个为待机动画,另一个为讲话动画。
  图像本身必须平均分成三格。 把这些图像命名为
  
  文件名_idle.png  << 待机
  文件名_talk.png  << 讲话
  
  -----------------------------------------------------------------------------
  *) 可用脚本:
  -----------------------------------------------------------------------------
  显示动态立绘的脚本
  
  - set_portrait(文件名, 位置, 反转, 激活)
    用于设置立绘,以下为解释
    
    *) 文件名    >> 图片的文件名,必须放在英文引号里(""). 
                    不用填入 _talk 或 _idle.
    *) 位置      >> 设定立绘位置. 请在 A (左), B (右), 和 C (中)中选择一个
    *) 反转      >> 图片是否左右反转? 填入 true/false. 也可以不用写.
                    默认为false
    *) 激活      >> 是否激活图像?  true时, 当文本逐个现实时,立绘会“讲话”
                    . (默认 : true)
       
  - remove_potrait(位置)
    移除一个立绘. 将"位置"替换为 A, B, 或 C
  
  - active_portrait(位置)
    激活一个立绘. 将"位置"替换为 A, B, 或 C
    
  - clear_portrait
    移除全部立绘,建议在对话结束后都使用一次。
    
  - $game_system.portrait_ypos[位置] = 数值
    重新定位当前显示肖像的位置。
    将"位置替换为" (:A, :B, :C). 将"数值"替换为数字. e.g,
    
    $game_system.portrait_ypos[:B] = 60
  
  -----------------------------------------------------------------------------
  使用规定 :
  署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
  如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
=end
  
 
 复制代码# =============================================================================
# TheoAllen - 动态立绘
# Version : 1.3
# Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
# (English Documentation)
# =============================================================================
($imported ||= {})[:Theo_AnimPortrait] = true
# =============================================================================
# Change Logs:
# -----------------------------------------------------------------------------
# 2014.05.18 - Bugfix, Talk refresh rate wont affect rate
# 2014.01.31 - Added screen y reposition
#            - Show portrait in bottom when placing message window in top
# 2014.01.08 - Added show picture in middle
# 2013.11.14 - Dimmed inactive portrait
#            - Bugfix, when remove portrait
# 2013.10.18 - Finished Script
# =============================================================================
=begin
  -----------------------------------------------------------------------------
  *) 介绍:
  -----------------------------------------------------------------------------
  本脚本可以简单地在对话中显示动态立绘
  
  -----------------------------------------------------------------------------
  *) 使用方法 :
  -----------------------------------------------------------------------------
  本脚本放在插件脚本之下,main之上
  
  准备两张任意尺寸的图片。一个为待机动画,另一个为讲话动画。
  图像本身必须平均分成三格。 把这些图像命名为
  
  文件名_idle.png  << 待机
  文件名_talk.png  << 讲话
  
  -----------------------------------------------------------------------------
  *) 可用脚本:
  -----------------------------------------------------------------------------
  显示动态立绘的脚本
  
  - set_portrait(文件名, 位置, 反转, 激活)
    用于设置立绘,以下为解释
    
    *) 文件名    >> 图片的文件名,必须放在英文引号里(""). 
                    不用填入 _talk 或 _idle.
    *) 位置      >> 设定立绘位置. 请在 A (左), B (右), 和 C (中)中选择一个
    *) 反转      >> 图片是否左右反转? 填入 true/false. 也可以不用写.
                    默认为false
    *) 激活      >> 是否激活图像?  true时, 当文本逐个现实时,立绘会“讲话”
                    . (默认 : true)
       
  - remove_potrait(位置)
    移除一个立绘. 将"位置"替换为 A, B, 或 C
  
  - active_portrait(位置)
    激活一个立绘. 将"位置"替换为 A, B, 或 C
    
  - clear_portrait
    移除全部立绘,建议在对话结束后都使用一次。
    
  - $game_system.portrait_ypos[位置] = 数值
    重新定位当前显示肖像的位置。
    将"位置替换为" (:A, :B, :C). 将"数值"替换为数字. e.g,
    
    $game_system.portrait_ypos[:B] = 60
  
  -----------------------------------------------------------------------------
  使用规定 :
  署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
  如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
=end
# =============================================================================
# 设定
# =============================================================================
module Theo
  module AnimePortrait
    
  # --------------------------------------------------------------------------
    Talk_Refresh_Rate = 4 
  # 当前激活立绘的刷新率。如果你设定为4,则图像会每4个字符出现后刷新一次。
  # 默认值为4.
  # --------------------------------------------------------------------------
  
  # --------------------------------------------------------------------------
    Idle_Interval = [20,120]
  # 待机动画的间隔等待时间. 格式为 [绝对等待时间, 随机等待时间]
  #
  # *) 绝对等待时间    >> 绝对等待时间(帧)
  # *) 随机等待时间    >> 随机等待时间(帧)
  #
  # 如果你设定为 [20,120] 意为等待动画之间的间隔 = 20帧 + 0~120的随机值
  # (默认 : [20,120])
  #
  # 注意 : 60 帧 = 1 秒
  # --------------------------------------------------------------------------
    
  # --------------------------------------------------------------------------
    Use_Dim   = true    # 是否使用暗淡化效果
    Dim_Power = 90      # 暗淡强度 (默认 : 90)
  # --------------------------------------------------------------------------
  # 暗淡效果用于"不讲话"的那个立绘
  # --------------------------------------------------------------------------
  end
end
# =============================================================================
# 设定结束
# =============================================================================
class Game_System
  attr_reader :portrait_ypos
  
  alias theo_animportrait_init initialize
  def initialize
    theo_animportrait_init
    @portrait_ypos = {
    :A => 0,
    :B => 0,
    :C => 0,
    }
  end
  
end
class Game_Interpreter
  A = :A  # Kiri
  B = :B  # Kanan
  C = :C  # Tengah
  
  def set_portrait(filename, pos, flip = false, active = true)
    $game_message.animportrait_name[pos] = [filename, flip]
    $game_message.active_portrait = pos if active
  end
  
  def clear_portrait
    $game_message.reset_animportrait
  end
  
  def remove_portrait(pos)
    $game_message.animportrait_name[pos][0] = ""
  end
  
  def active_portrait(pos)
    $game_message.active_portrait = pos
  end
  
end
class Game_Message
  attr_accessor :active_portrait
  attr_reader :animportrait_name
  
  alias theo_animportrait_init initialize
  def initialize
    theo_animportrait_init
    reset_animportrait
    @active_portrait = :A
  end
  
  def reset_animportrait
    @animportrait_name = {
      :A => ["", false],
      :B => ["", false],
      :C => ["", false],
    }
  end
  
end
class AnimPortrait < Sprite
  include Theo::AnimePortrait
  Dimmed_Color = Color.new(0,0,0,Dim_Power)
  Normal_Color = Color.new(0,0,0,0)
  attr_accessor :self_switch  # Self Activation ~
  
  def initialize(pos, msg_window, viewport = nil)
    super(viewport)
    self.z = 150
    @msg_window = msg_window
    @pos = pos
    @self_switch = false
    @idle_pattern = 0
    @fiber = nil
    init_bitmap
    generate_idle_count
  end
  
  def init_bitmap
    @filename = img_name
    self.bitmap = Cache.system(@filename)
    self.mirror = $game_message.animportrait_name[@pos][1]
    case @pos
    when :A
      self.x = 0
    when :B
      self.x = Graphics.width - width
    when :C
      self.x = (Graphics.width - width) / 2
    end
  end
  
  def img_name
    str = $game_message.animportrait_name[@pos][0]
    return "" if str.empty?
    return str + (active? ? "_talk" : "_idle")
  end
  
  def bitmap=(bmp)
    super
    src_rect.width = bitmap.width / 3
  end
  
  def generate_idle_count
    @idle_count = random_idle_number
  end
  
  def random_idle_number
    return Idle_Interval[0] + rand(Idle_Interval[1])
  end
  
  def update
    super
    self.y = ypos_case
    self.opacity = @msg_window.openness
    update_bitmap
    update_color if Use_Dim
    update_idle unless active?
  end
  
  def ypos_case
    return Graphics.height - height + $game_system.portrait_ypos[@pos] if
      $game_message.position == 0
    return @msg_window.y - height + $game_system.portrait_ypos[@pos]
  end
  
  def update_bitmap
    if @filename != img_name
      init_bitmap
    end
  end
  
  def update_color
    if pos_active?
      self.color = Normal_Color
    else
      self.color = Dimmed_Color
    end
  end
  
  def update_active
    @fiber = nil if @fiber
    set_src_rect(rand(3))
  end
  
  def active?
    return pos_active? && self_switch
  end
  
  def pos_active?
    @pos == $game_message.active_portrait
  end
  
  def update_idle
    if @fiber
      @fiber.resume
    elsif @idle_count == 0
      @fiber = Fiber.new { fiber_idle }
    else
      @idle_count -= 1
    end
  end
  
  def fiber_idle
    setup_idle_anim
    update_idle_src_rect
    terminate_idle_anim
  end
  
  def setup_idle_anim
    set_src_rect(0)
  end
  
  def update_idle_src_rect
    random_wait
    set_src_rect(1)
    random_wait
    set_src_rect(2)
    random_wait
    set_src_rect(1)
    random_wait
    set_src_rect(0)
    random_wait
  end
  
  def set_src_rect(amount)
    @pattern = amount
    src_rect.x = @pattern * bitmap.width/3
  end
  
  def random_wait
    (2 + rand(3)).times { Fiber.yield }
  end
  
  def terminate_idle_anim
    @fiber = nil
    generate_idle_count
  end
  
  def dispose
    bitmap.dispose
    super
  end
  
end
class Window_Message < Window_Base
  
  alias theo_animportrait_init initialize
  def initialize
    theo_animportrait_init
    create_animportrait
  end
  
  def create_animportrait
    @animportrait = {
      :A => AnimPortrait.new(:A, self, viewport),
      :B => AnimPortrait.new(:B, self, viewport),
      :C => AnimPortrait.new(:C, self, viewport),
    }
    @talk_anim = 0
  end
  
  def active_portrait
    @animportrait[$game_message.active_portrait]
  end
  
  alias theo_animportrait_process_all_text process_all_text
  def process_all_text
    active_portrait.self_switch = true
    theo_animportrait_process_all_text
  end
  
  alias theo_animportrait_updt_show_fast update_show_fast
  def update_show_fast
    theo_animportrait_updt_show_fast
    active_portrait.set_src_rect(0) if Input.trigger?(:C)
  end
  
  alias theo_animportrait_wait_for_one_char wait_for_one_character
  def wait_for_one_character
    theo_animportrait_wait_for_one_char
    @talk_anim += 1
    refrate = Theo::AnimePortrait::Talk_Refresh_Rate
    active_portrait.update_active if @talk_anim % refrate == 0
  end
  
  alias theo_animportrait_process_input process_input
  def process_input
    active_portrait.set_src_rect(0)
    active_portrait.self_switch = false
    theo_animportrait_process_input
  end
  
  alias theo_animportrait_update update
  def update
    theo_animportrait_update
    @animportrait.values.each {|img| img.update }
  end
  
  alias theo_animportrait_dispose dispose
  def dispose
    theo_animportrait_dispose
    @animportrait.values.each {|img| img.dispose }
  end
  
  alias theo_animportrait_wait wait
  def wait(duration)
    active_portrait.set_src_rect(0)
    theo_animportrait_wait(duration)
  end
  
end
 
 
 
 
 
 | 
 |