- 累计送礼:
- 0 个
- 累计收礼:
- 1 个
TA的每日心情 | 开心 2026-7-12 04:10 |
|---|
签到天数: 209 天 连续签到: 2 天 [LV.7]常住居民III

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


|
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: - # coding: utf-8
- #===============================================================================
- # ■ Tweenアニメーションさん for RGSS3
- #-------------------------------------------------------------------------------
- # 2013/05/11 Ru/むっくRu
- #-------------------------------------------------------------------------------
- # FlashなどではおなじみのTweenアニメーションを扱う機能をRGSS3に追加します。
- # 指定したプロパティを指定時間で変化させることが可能になります。
- # 詳細は解説記事をどうぞ。
- #-------------------------------------------------------------------------------
- # 【注意】
- # このスクリプトはRGSSに機能を追加するものであり、
- # このスクリプトだけで何か効果があるわけではありません。
- #-------------------------------------------------------------------------------
- # 【更新履歴】
- # 2013/05/11 メソッド名間違えていたのを修正
- # 2013/05/06 公開
- #-------------------------------------------------------------------------------
- #===============================================================================
- # ↓ 以下、スクリプト部 ↓
- #===============================================================================
- module HZM_VXA
- module Tween
- #---------------------------------------------------------------------------
- # ■ 全Tweenアニメーションの管理
- #---------------------------------------------------------------------------
- module Manager
- #-------------------------------------------------------------------------
- # ● 初期化
- #-------------------------------------------------------------------------
- def self.init
- @list = []
- end
- #-------------------------------------------------------------------------
- # ● フレーム更新
- #-------------------------------------------------------------------------
- def self.update
- @list.delete_if do |animation|
- animation.update_from_manager
- !animation.play?
- end
- end
- #-------------------------------------------------------------------------
- # ● アニメーションの追加
- #-------------------------------------------------------------------------
- def self.push(animation)
- @list.push animation unless @list.include?(animation)
- end
- #-------------------------------------------------------------------------
- # ● 再生中?
- #-------------------------------------------------------------------------
- def self.play?
- @list.size > 0
- end
- end
- #---------------------------------------------------------------------------
- # ■ 各Tweenアニメーション用クラス
- #---------------------------------------------------------------------------
- class Animation
- #-------------------------------------------------------------------------
- # ● 生成
- #-------------------------------------------------------------------------
- def initialize(obj, *params)
- @obj = obj
- @animation_params = params
- @playing = false
- end
- #-------------------------------------------------------------------------
- # ● 再生開始
- #-------------------------------------------------------------------------
- def play
- @playing = true
- @timer = 0
- @index = 0
- init_animation
- Manager.push(self)
- end
- #-------------------------------------------------------------------------
- # ● 再生停止
- #-------------------------------------------------------------------------
- def stop
- @playing = false
- end
- #-------------------------------------------------------------------------
- # ● 再生中か
- #-------------------------------------------------------------------------
- def play?
- @playing
- end
- #-------------------------------------------------------------------------
- # ● 更新(Managerから呼び出される)
- #-------------------------------------------------------------------------
- def update_from_manager
- # 停止中は処理しない
- return unless @playing
- # 再生時間の増加
- @timer += 1
- # 各要素を更新
- begin
- @playing_params.each do |key, value|
- n = @transition_method.call(@timer, value[1], value[2], @timer_max)
- value[0].call(n.to_i)
- end
- rescue RGSSError
- # 既に解放済みなので強制終了する
- stop
- return
- end
- # 再生が完了したら次のステップへ
- unless @timer < @timer_max
- @index += 1
- init_animation
- end
- end
- private
- #-------------------------------------------------------------------------
- # ● アニメーション開始の準備
- #-------------------------------------------------------------------------
- def init_animation
- # 全アニメーションが終了していたら再生停止
- return stop unless @index < @animation_params.size
- # 初期化
- @timer = 0.0
- # 再生時間の確認
- @timer_max = @animation_params[@index][:time].to_f
- # トランジションメソッドの確認
- transition = @animation_params[@index][:transition]
- transition = nil if transition == :default
- if transition == nil
- transition = Transition.default
- elsif transition.class == Symbol
- begin
- transition = Transition.method_cache(transition)
- rescue
- transition = Transition.default
- end
- end
- @transition_method = transition
- # 各要素の初期値、ターゲット値を準備
- params = {}
- @animation_params[@index].each do |key, value|
- next if key == :time or key == :transition
- method = @obj.method("#{key}=".to_sym)
- start = @obj.method(key).call.to_i
- change = value.to_i - start
- params[key] = [method, start.to_f, change.to_f]
- end
- @playing_params = params
- true
- end
- end
- #---------------------------------------------------------------------------
- # ■ 標準トランジション用モジュール
- # 新たに追加したくなった場合は、ここに追加する
- #---------------------------------------------------------------------------
- # 参考元URL
- # http://www.robertpenner.com/easing/
- # http://gizma.com/easing/
- #---------------------------------------------------------------------------
- module Transition
- @@caches = {}
- #-------------------------------------------------------------------------
- # ● 標準トランジションの取得
- #-------------------------------------------------------------------------
- def self.default
- self.method_cache(:linear)
- end
- #-------------------------------------------------------------------------
- # ● メソッドキャッシュの取得
- #-------------------------------------------------------------------------
- def self.method_cache(name)
- @@caches[name] ||= self.method(name)
- end
- #-------------------------------------------------------------------------
- # ● Linear
- #-------------------------------------------------------------------------
- def self.linear(time, begin_value, change_value, duration)
- begin_value + change_value * time / duration
- end
- #-------------------------------------------------------------------------
- # ● Easing In Quad
- #-------------------------------------------------------------------------
- def self.ease_in_quad(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * time * time
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Quad
- #-------------------------------------------------------------------------
- def self.ease_out_quad(time, begin_value, change_value, duration)
- time /= duration
- begin_value - change_value * time * (time - 2)
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Quad
- #-------------------------------------------------------------------------
- def self.ease_in_out_quad(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if time < 1
- begin_value + change_value * time * time
- else
- time -= 1
- begin_value - change_value * (time * (time - 2) - 1)
- end
- end
- #-------------------------------------------------------------------------
- # ● Easing In Cubic
- #-------------------------------------------------------------------------
- def self.ease_in_cubic(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (time ** 3)
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Cubic
- #-------------------------------------------------------------------------
- def self.ease_out_cubic(time, begin_value, change_value, duration)
- time /= duration
- time -= 1
- begin_value + change_value * (time ** 3 + 1)
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Cubic
- #-------------------------------------------------------------------------
- def self.ease_in_out_cubic(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if time < 1
- begin_value + change_value * (time ** 3)
- else
- time -= 2
- begin_value + change_value * (time ** 3 + 2)
- end
- end
- #-------------------------------------------------------------------------
- # ● Easing In Quartic
- #-------------------------------------------------------------------------
- def self.ease_in_quart(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (time ** 4)
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Quartic
- #-------------------------------------------------------------------------
- def self.ease_out_quart(time, begin_value, change_value, duration)
- time /= duration
- time -= 1
- begin_value - change_value * (time ** 4 - 1)
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Quartic
- #-------------------------------------------------------------------------
- def self.ease_in_out_quart(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if time < 1
- begin_value + change_value * (time ** 4)
- else
- time -= 2
- begin_value - change_value * (time ** 4 - 2)
- end
- end
- #-------------------------------------------------------------------------
- # ● Easing In Quintic
- #-------------------------------------------------------------------------
- def self.ease_in_quint(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (time ** 5)
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Quintic
- #-------------------------------------------------------------------------
- def self.ease_out_quint(time, begin_value, change_value, duration)
- time /= duration
- time -= 1
- begin_value + change_value * (time ** 5 + 1)
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Quintic
- #-------------------------------------------------------------------------
- def self.ease_in_out_quint(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if time < 1
- begin_value + change_value * (time ** 5)
- else
- time -= 2
- begin_value + change_value * (time ** 5 + 2)
- end
- end
- #-------------------------------------------------------------------------
- # ● Easing In Sine
- #-------------------------------------------------------------------------
- def self.ease_in_sine(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (1 - Math.cos(time * (Math::PI / 2)))
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Sine
- #-------------------------------------------------------------------------
- def self.ease_out_sine(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * Math.sin(time * (Math::PI / 2))
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Sine
- #-------------------------------------------------------------------------
- def self.ease_in_out_sine(time, begin_value, change_value, duration)
- time /= duration
- begin_value - change_value / 2 * (Math.cos(Math::PI * time) - 1)
- end
- #-------------------------------------------------------------------------
- # ● Easing In Exponential
- #-------------------------------------------------------------------------
- def self.ease_in_expo(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (2 ** (10 * (time - 1)))
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Exponential
- #-------------------------------------------------------------------------
- def self.ease_out_expo(time, begin_value, change_value, duration)
- time /= duration
- begin_value + change_value * (1 - (2 ** (-10 * time)))
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Exponential
- #-------------------------------------------------------------------------
- def self.ease_in_out_expo(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if time < 1
- begin_value + change_value * (2 ** (10 * (time - 1)))
- else
- begin_value + change_value * (-2 ** (10 * (time - 1)) + 2)
- end
- end
- #-------------------------------------------------------------------------
- # ● Easing In Circular
- #-------------------------------------------------------------------------
- def self.ease_in_circ(time, begin_value, change_value, duration)
- time /= duration
- begin_value - change_value * (Math.sqrt(1 - time * time) - 1)
- end
- #-------------------------------------------------------------------------
- # ● Easing Out Circular
- #-------------------------------------------------------------------------
- def self.ease_out_circ(time, begin_value, change_value, duration)
- time /= duration
- time -= 1
- begin_value + change_value * Math.sqrt(1 - time * time)
- end
- #-------------------------------------------------------------------------
- # ● Easing In/Out Circular
- #-------------------------------------------------------------------------
- def self.ease_in_out_circ(time, begin_value, change_value, duration)
- time /= duration / 2
- change_value /= 2
- if (time < 1)
- begin_value - change_value * (Math.sqrt(1 - time * time) - 1)
- else
- begin_value + change_value * (Math.sqrt(1 - time * time) + 1)
- end
- end
- end
- end
- end
- #===============================================================================
- # ■ SceneManager
- #===============================================================================
- class << SceneManager
- #-----------------------------------------------------------------------------
- # ● 実行(エイリアス)
- #-----------------------------------------------------------------------------
- alias hzm_vxa_tween_run run
- def run
- HZM_VXA::Tween::Manager.init
- hzm_vxa_tween_run
- end
- end
- #===============================================================================
- # ■ Scene_Base
- #===============================================================================
- class Scene_Base
- #-----------------------------------------------------------------------------
- # ● フレーム更新(基本)(エイリアス)
- #-----------------------------------------------------------------------------
- alias hzm_vxa_tween_update_basic update_basic
- def update_basic
- HZM_VXA::Tween::Manager.update
- hzm_vxa_tween_update_basic
- end
- end
复制代码
Animate menu when opened sample script
Code: - # メニュー画面を開いたときにうぃんうぃんするスクリプト
- class Scene_Menu < Scene_MenuBase
- ANIMATION_TIME = 15
- #-----------------------------------------------------------------------------
- # ● 開始処理
- #-----------------------------------------------------------------------------
- alias hzm_vxa_tween_sample_start start
- def start
- hzm_vxa_tween_sample_start
- unless Window_MenuCommand.last_command_symbol
- # 各アニメーションを設定
- anim_command = HZM_VXA::Tween::Animation.new(@command_window, {
- :time => ANIMATION_TIME,
- :transition => :ease_out_quad,
- :x => @command_window.x,
- :y => @command_window.y,
- })
- anim_gold = HZM_VXA::Tween::Animation.new(@gold_window, {
- :time => ANIMATION_TIME,
- :transition => :ease_out_quad,
- :x => @gold_window.x,
- :y => @gold_window.y,
- })
- anim_status = HZM_VXA::Tween::Animation.new(@status_window, {
- :time => ANIMATION_TIME,
- :transition => :ease_out_quad,
- :x => @status_window.x,
- :y => @status_window.y,
- })
- # 初期値を指定
- @command_window.x = 0 - @command_window.width
- @command_window.y = 0 - @command_window.width
- @gold_window.x = 0 - @gold_window.width
- @gold_window.y = Graphics.height + @gold_window.width
- @status_window.x = Graphics.width
- # アニメーション開始
- anim_command.play
- anim_gold.play
- anim_status.play
- end
- end
- end
- class Window_MenuCommand < Window_Command
- #-----------------------------------------------------------------------------
- # ● コマンド選択位置の取得(クラスメソッド)(独自)
- #-----------------------------------------------------------------------------
- def self.last_command_symbol
- @@last_command_symbol
- end
- 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/ |
|