设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 110|回复: 0

[转载发布] Tween Animation

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-2 18:47:54 | 显示全部楼层 |阅读模式
    Tween Animation 2013/05/11

    Creator name: Ru/むっくRu (Rutan)

    Overview
    Adds tween animation functionality to RGSS3 (Animate menu sample script included)

    Preview

    https://www.youtube.com/embed/PH40FlmLxxw


    Note: If you're knowledgeable in RGSS3 and Tween animation you could use these transitions.

    Available transition
    :linear
    :ease_in_quad
    :ease_out_quad
    :ease_in_out_quad
    :ease_in_cubic
    :ease_out_cubic
    :ease_in_out_cubic
    :ease_in_quart
    :ease_out_quart
    :ease_in_out_quart
    :ease_in_quint
    :ease_out_quint
    :ease_in_out_quint
    :ease_in_sine
    :ease_out_sine
    :ease_in_out_sine
    :ease_in_expo
    :ease_out_expo
    :ease_in_out_expo
    :ease_in_circ
    :ease_out_circ
    :ease_in_out_circ

    Script: GitHub Gist - 【Tweenアニメーションさん for RGSS3】

    How to use
    Paste this script above Main.

                    Code:       
    1. # coding: utf-8
    2. #===============================================================================
    3. # ■ Tweenアニメーションさん for RGSS3
    4. #-------------------------------------------------------------------------------
    5. #  2013/05/11 Ru/むっくRu
    6. #-------------------------------------------------------------------------------
    7. #  FlashなどではおなじみのTweenアニメーションを扱う機能をRGSS3に追加します。
    8. #  指定したプロパティを指定時間で変化させることが可能になります。
    9. #  詳細は解説記事をどうぞ。
    10. #-------------------------------------------------------------------------------
    11. # 【注意】
    12. #  このスクリプトはRGSSに機能を追加するものであり、
    13. #  このスクリプトだけで何か効果があるわけではありません。
    14. #-------------------------------------------------------------------------------
    15. # 【更新履歴】
    16. # 2013/05/11 メソッド名間違えていたのを修正
    17. # 2013/05/06 公開
    18. #-------------------------------------------------------------------------------
    19. #===============================================================================
    20. # ↓ 以下、スクリプト部 ↓
    21. #===============================================================================
    22. module HZM_VXA
    23.   module Tween
    24.     #---------------------------------------------------------------------------
    25.     # ■ 全Tweenアニメーションの管理
    26.     #---------------------------------------------------------------------------
    27.     module Manager
    28.       #-------------------------------------------------------------------------
    29.       # ● 初期化
    30.       #-------------------------------------------------------------------------
    31.       def self.init
    32.         @list = []
    33.       end
    34.       #-------------------------------------------------------------------------
    35.       # ● フレーム更新
    36.       #-------------------------------------------------------------------------
    37.       def self.update
    38.         @list.delete_if do |animation|
    39.           animation.update_from_manager
    40.           !animation.play?
    41.         end
    42.       end
    43.       #-------------------------------------------------------------------------
    44.       # ● アニメーションの追加
    45.       #-------------------------------------------------------------------------
    46.       def self.push(animation)
    47.         @list.push animation unless @list.include?(animation)
    48.       end
    49.       #-------------------------------------------------------------------------
    50.       # ● 再生中?
    51.       #-------------------------------------------------------------------------
    52.       def self.play?
    53.         @list.size > 0
    54.       end
    55.     end
    56.     #---------------------------------------------------------------------------
    57.     # ■ 各Tweenアニメーション用クラス
    58.     #---------------------------------------------------------------------------
    59.     class Animation
    60.       #-------------------------------------------------------------------------
    61.       # ● 生成
    62.       #-------------------------------------------------------------------------
    63.       def initialize(obj, *params)
    64.         @obj = obj
    65.         @animation_params = params
    66.         @playing = false
    67.       end
    68.       #-------------------------------------------------------------------------
    69.       # ● 再生開始
    70.       #-------------------------------------------------------------------------
    71.       def play
    72.         @playing = true
    73.         @timer   = 0
    74.         @index   = 0
    75.         init_animation
    76.         Manager.push(self)
    77.       end
    78.       #-------------------------------------------------------------------------
    79.       # ● 再生停止
    80.       #-------------------------------------------------------------------------
    81.       def stop
    82.         @playing = false
    83.       end
    84.       #-------------------------------------------------------------------------
    85.       # ● 再生中か
    86.       #-------------------------------------------------------------------------
    87.       def play?
    88.         @playing
    89.       end
    90.       #-------------------------------------------------------------------------
    91.       # ● 更新(Managerから呼び出される)
    92.       #-------------------------------------------------------------------------
    93.       def update_from_manager
    94.         # 停止中は処理しない
    95.         return unless @playing
    96.         # 再生時間の増加
    97.         @timer += 1
    98.         # 各要素を更新
    99.         begin
    100.           @playing_params.each do |key, value|
    101.             n = @transition_method.call(@timer, value[1], value[2], @timer_max)
    102.             value[0].call(n.to_i)
    103.           end
    104.         rescue RGSSError
    105.           # 既に解放済みなので強制終了する
    106.           stop
    107.           return
    108.         end
    109.         # 再生が完了したら次のステップへ
    110.         unless @timer < @timer_max
    111.           @index += 1
    112.           init_animation
    113.         end
    114.       end
    115.       private
    116.       #-------------------------------------------------------------------------
    117.       # ● アニメーション開始の準備
    118.       #-------------------------------------------------------------------------
    119.       def init_animation
    120.         # 全アニメーションが終了していたら再生停止
    121.         return stop unless @index < @animation_params.size
    122.         # 初期化
    123.         @timer = 0.0
    124.         # 再生時間の確認
    125.         @timer_max = @animation_params[@index][:time].to_f
    126.         # トランジションメソッドの確認
    127.         transition = @animation_params[@index][:transition]
    128.         transition = nil if transition == :default
    129.         if transition == nil
    130.           transition = Transition.default
    131.         elsif transition.class == Symbol
    132.           begin
    133.             transition = Transition.method_cache(transition)
    134.           rescue
    135.             transition = Transition.default
    136.           end
    137.         end
    138.         @transition_method = transition
    139.         # 各要素の初期値、ターゲット値を準備
    140.         params = {}
    141.         @animation_params[@index].each do |key, value|
    142.           next if key == :time or key == :transition
    143.           method = @obj.method("#{key}=".to_sym)
    144.           start  = @obj.method(key).call.to_i
    145.           change = value.to_i - start
    146.           params[key] = [method, start.to_f, change.to_f]
    147.         end
    148.         @playing_params = params
    149.         true
    150.       end
    151.     end
    152.     #---------------------------------------------------------------------------
    153.     # ■ 標準トランジション用モジュール
    154.     #    新たに追加したくなった場合は、ここに追加する
    155.     #---------------------------------------------------------------------------
    156.     # 参考元URL
    157.     # http://www.robertpenner.com/easing/
    158.     # http://gizma.com/easing/
    159.     #---------------------------------------------------------------------------
    160.     module Transition
    161.       @@caches = {}
    162.       #-------------------------------------------------------------------------
    163.       # ● 標準トランジションの取得
    164.       #-------------------------------------------------------------------------
    165.       def self.default
    166.         self.method_cache(:linear)
    167.       end
    168.       #-------------------------------------------------------------------------
    169.       # ● メソッドキャッシュの取得
    170.       #-------------------------------------------------------------------------
    171.       def self.method_cache(name)
    172.         @@caches[name] ||= self.method(name)
    173.       end
    174.       #-------------------------------------------------------------------------
    175.       # ● Linear
    176.       #-------------------------------------------------------------------------
    177.       def self.linear(time, begin_value, change_value, duration)
    178.         begin_value + change_value * time / duration
    179.       end
    180.       #-------------------------------------------------------------------------
    181.       # ● Easing In Quad
    182.       #-------------------------------------------------------------------------
    183.       def self.ease_in_quad(time, begin_value, change_value, duration)
    184.         time /= duration
    185.         begin_value + change_value * time * time
    186.       end
    187.       #-------------------------------------------------------------------------
    188.       # ● Easing Out Quad
    189.       #-------------------------------------------------------------------------
    190.       def self.ease_out_quad(time, begin_value, change_value, duration)
    191.         time /= duration
    192.         begin_value - change_value * time * (time - 2)
    193.       end
    194.       #-------------------------------------------------------------------------
    195.       # ● Easing In/Out Quad
    196.       #-------------------------------------------------------------------------
    197.       def self.ease_in_out_quad(time, begin_value, change_value, duration)
    198.         time /= duration / 2
    199.         change_value /= 2
    200.         if time < 1
    201.           begin_value + change_value * time * time
    202.         else
    203.           time -= 1
    204.           begin_value - change_value * (time * (time - 2) - 1)
    205.         end
    206.       end
    207.       #-------------------------------------------------------------------------
    208.       # ● Easing In Cubic
    209.       #-------------------------------------------------------------------------
    210.       def self.ease_in_cubic(time, begin_value, change_value, duration)
    211.         time /= duration
    212.         begin_value + change_value * (time ** 3)
    213.       end
    214.       #-------------------------------------------------------------------------
    215.       # ● Easing Out Cubic
    216.       #-------------------------------------------------------------------------
    217.       def self.ease_out_cubic(time, begin_value, change_value, duration)
    218.         time /= duration
    219.         time -= 1
    220.         begin_value + change_value * (time ** 3 + 1)
    221.       end
    222.       #-------------------------------------------------------------------------
    223.       # ● Easing In/Out Cubic
    224.       #-------------------------------------------------------------------------
    225.       def self.ease_in_out_cubic(time, begin_value, change_value, duration)
    226.         time /= duration / 2
    227.         change_value /= 2
    228.         if time < 1
    229.           begin_value + change_value * (time ** 3)
    230.         else
    231.           time -= 2
    232.           begin_value + change_value * (time ** 3 + 2)
    233.         end
    234.       end
    235.       #-------------------------------------------------------------------------
    236.       # ● Easing In Quartic
    237.       #-------------------------------------------------------------------------
    238.       def self.ease_in_quart(time, begin_value, change_value, duration)
    239.         time /= duration
    240.         begin_value + change_value * (time ** 4)
    241.       end
    242.       #-------------------------------------------------------------------------
    243.       # ● Easing Out Quartic
    244.       #-------------------------------------------------------------------------
    245.       def self.ease_out_quart(time, begin_value, change_value, duration)
    246.         time /= duration
    247.         time -= 1
    248.         begin_value - change_value * (time ** 4 - 1)
    249.       end
    250.       #-------------------------------------------------------------------------
    251.       # ● Easing In/Out Quartic
    252.       #-------------------------------------------------------------------------
    253.       def self.ease_in_out_quart(time, begin_value, change_value, duration)
    254.         time /= duration / 2
    255.         change_value /= 2
    256.         if time < 1
    257.           begin_value + change_value * (time ** 4)
    258.         else
    259.           time -= 2
    260.           begin_value - change_value * (time ** 4 - 2)
    261.         end
    262.       end
    263.       #-------------------------------------------------------------------------
    264.       # ● Easing In Quintic
    265.       #-------------------------------------------------------------------------
    266.       def self.ease_in_quint(time, begin_value, change_value, duration)
    267.         time /= duration
    268.         begin_value + change_value * (time ** 5)
    269.       end
    270.       #-------------------------------------------------------------------------
    271.       # ● Easing Out Quintic
    272.       #-------------------------------------------------------------------------
    273.       def self.ease_out_quint(time, begin_value, change_value, duration)
    274.         time /= duration
    275.         time -= 1
    276.         begin_value + change_value * (time ** 5 + 1)
    277.       end
    278.       #-------------------------------------------------------------------------
    279.       # ● Easing In/Out Quintic
    280.       #-------------------------------------------------------------------------
    281.       def self.ease_in_out_quint(time, begin_value, change_value, duration)
    282.         time /= duration / 2
    283.         change_value /= 2
    284.         if time < 1
    285.           begin_value + change_value * (time ** 5)
    286.         else
    287.           time -= 2
    288.           begin_value + change_value * (time ** 5 + 2)
    289.         end
    290.       end
    291.       #-------------------------------------------------------------------------
    292.       # ● Easing In Sine
    293.       #-------------------------------------------------------------------------
    294.       def self.ease_in_sine(time, begin_value, change_value, duration)
    295.         time /= duration
    296.         begin_value + change_value * (1 - Math.cos(time * (Math::PI / 2)))
    297.       end
    298.       #-------------------------------------------------------------------------
    299.       # ● Easing Out Sine
    300.       #-------------------------------------------------------------------------
    301.       def self.ease_out_sine(time, begin_value, change_value, duration)
    302.         time /= duration
    303.         begin_value + change_value * Math.sin(time * (Math::PI / 2))
    304.       end
    305.       #-------------------------------------------------------------------------
    306.       # ● Easing In/Out Sine
    307.       #-------------------------------------------------------------------------
    308.       def self.ease_in_out_sine(time, begin_value, change_value, duration)
    309.         time /= duration
    310.         begin_value - change_value / 2 * (Math.cos(Math::PI * time) - 1)
    311.       end
    312.       #-------------------------------------------------------------------------
    313.       # ● Easing In Exponential
    314.       #-------------------------------------------------------------------------
    315.       def self.ease_in_expo(time, begin_value, change_value, duration)
    316.         time /= duration
    317.         begin_value + change_value * (2 ** (10 * (time - 1)))
    318.       end
    319.       #-------------------------------------------------------------------------
    320.       # ● Easing Out Exponential
    321.       #-------------------------------------------------------------------------
    322.       def self.ease_out_expo(time, begin_value, change_value, duration)
    323.         time /= duration
    324.         begin_value + change_value * (1 - (2 ** (-10 * time)))
    325.       end
    326.       #-------------------------------------------------------------------------
    327.       # ● Easing In/Out Exponential
    328.       #-------------------------------------------------------------------------
    329.       def self.ease_in_out_expo(time, begin_value, change_value, duration)
    330.         time /= duration / 2
    331.         change_value /= 2
    332.         if time < 1
    333.           begin_value + change_value * (2 ** (10 * (time - 1)))
    334.         else
    335.           begin_value + change_value * (-2 ** (10 * (time - 1)) + 2)
    336.         end
    337.       end
    338.       #-------------------------------------------------------------------------
    339.       # ● Easing In Circular
    340.       #-------------------------------------------------------------------------
    341.       def self.ease_in_circ(time, begin_value, change_value, duration)
    342.         time /= duration
    343.         begin_value - change_value * (Math.sqrt(1 - time * time) - 1)
    344.       end
    345.       #-------------------------------------------------------------------------
    346.       # ● Easing Out Circular
    347.       #-------------------------------------------------------------------------
    348.       def self.ease_out_circ(time, begin_value, change_value, duration)
    349.         time /= duration
    350.         time -= 1
    351.         begin_value + change_value * Math.sqrt(1 - time * time)
    352.       end
    353.       #-------------------------------------------------------------------------
    354.       # ● Easing In/Out Circular
    355.       #-------------------------------------------------------------------------
    356.       def self.ease_in_out_circ(time, begin_value, change_value, duration)
    357.         time /= duration / 2
    358.         change_value /= 2
    359.         if (time < 1)
    360.           begin_value - change_value * (Math.sqrt(1 - time * time) - 1)
    361.         else
    362.           begin_value + change_value * (Math.sqrt(1 - time * time) + 1)
    363.         end
    364.       end
    365.     end
    366.   end
    367. end
    368. #===============================================================================
    369. # ■ SceneManager
    370. #===============================================================================
    371. class << SceneManager
    372.   #-----------------------------------------------------------------------------
    373.   # ● 実行(エイリアス)
    374.   #-----------------------------------------------------------------------------
    375.   alias hzm_vxa_tween_run run
    376.   def run
    377.     HZM_VXA::Tween::Manager.init
    378.     hzm_vxa_tween_run
    379.   end
    380. end
    381. #===============================================================================
    382. # ■ Scene_Base
    383. #===============================================================================
    384. class Scene_Base
    385.   #-----------------------------------------------------------------------------
    386.   # ● フレーム更新(基本)(エイリアス)
    387.   #-----------------------------------------------------------------------------
    388.   alias hzm_vxa_tween_update_basic update_basic
    389.   def update_basic
    390.     HZM_VXA::Tween::Manager.update
    391.     hzm_vxa_tween_update_basic
    392.   end
    393. end
    复制代码


    Animate menu when opened sample script

                    Code:       
    1. # メニュー画面を開いたときにうぃんうぃんするスクリプト
    2. class Scene_Menu < Scene_MenuBase
    3.   ANIMATION_TIME = 15
    4.   #-----------------------------------------------------------------------------
    5.   # ● 開始処理
    6.   #-----------------------------------------------------------------------------
    7.   alias hzm_vxa_tween_sample_start start
    8.   def start
    9.     hzm_vxa_tween_sample_start
    10.     unless Window_MenuCommand.last_command_symbol
    11.       # 各アニメーションを設定
    12.       anim_command = HZM_VXA::Tween::Animation.new(@command_window, {
    13.         :time => ANIMATION_TIME,
    14.         :transition => :ease_out_quad,
    15.         :x => @command_window.x,
    16.         :y => @command_window.y,
    17.         })
    18.       anim_gold = HZM_VXA::Tween::Animation.new(@gold_window, {
    19.         :time => ANIMATION_TIME,
    20.         :transition => :ease_out_quad,
    21.         :x => @gold_window.x,
    22.         :y => @gold_window.y,
    23.         })
    24.       anim_status = HZM_VXA::Tween::Animation.new(@status_window, {
    25.         :time => ANIMATION_TIME,
    26.         :transition => :ease_out_quad,
    27.         :x => @status_window.x,
    28.         :y => @status_window.y,
    29.         })
    30.       # 初期値を指定
    31.       @command_window.x = 0 - @command_window.width
    32.       @command_window.y = 0 - @command_window.width
    33.       @gold_window.x = 0 - @gold_window.width
    34.       @gold_window.y = Graphics.height + @gold_window.width
    35.       @status_window.x = Graphics.width
    36.       # アニメーション開始
    37.       anim_command.play
    38.       anim_gold.play
    39.       anim_status.play
    40.     end
    41.   end
    42. end
    43. class Window_MenuCommand < Window_Command
    44.   #-----------------------------------------------------------------------------
    45.   # ● コマンド選択位置の取得(クラスメソッド)(独自)
    46.   #-----------------------------------------------------------------------------
    47.   def self.last_command_symbol
    48.     @@last_command_symbol
    49.   end
    50. end
    复制代码


    This could be improved..

    License - Public Domain

    Source
    https://torigoya.hatenadiary.jp/entry/20130506/rgss_tween


    本贴来自国际rpgmaker官方论坛作者:ovate处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/tween-animation.144301/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 09:25 , Processed in 0.100308 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表