Anime Lite Battle
Publicado em 11 de setembro de 2011.Segue um script para RPG Maker XP feito por Kuroneko_h (creio eu). Os comentários do script estão em japonês, mas pelo que consegui traduzir, ao manter o cache de animação freqüentemente utilizado, o processo de carregamento de imagens animadas durante a reprodução reduz o número de scripts utilizados, deixando o processo das animações das batalhas mais leves. Talvez seja algum tipo de anti-lag, sei lá… Se alguém souber, por favor compartilhe conosco!
#===============================================================================
# ■ アニメーション再生高速化処理
#===============================================================================
# よく使うアニメをキャッシュに保つことで、アニメ再生時の画像読み込みの処理を
# 軽減させるスクリプト郡です。
#===============================================================================
# ※注意事項
# ・Scene_Battleの再定義を行っていますので、
# 配置場所はScene_Battleより後にしてください。
#
# ・RPG::Spriteの再定義を行っています。詳細はソースを参照。
#-------------------------------------------------------------------------------
# 作成日 :2006/07/06
# 最終更新日:2006/09/21
# バージョン:ver 1.00
# 製作者 :黒猫白狼 (Kuroneko_h)
# サポート :http://cafe-df.2-d.jp/
#-------------------------------------------------------------------------------
# ◆更新履歴
# ☆2006/07/06 ver 1.00
# 公開
# ☆2006/09/21 ver 1.01
# プリロード機能実装。
#===============================================================================
module RPG
#---------------------------------------------------------------------------
# ● アニメ用キャッシュ部
#---------------------------------------------------------------------------
module Cache_Battle
#-----------------------------------------------------------------------
# ● フィールド定義
#-----------------------------------------------------------------------
@cache = {} # 画像キャッシュ
@last_count = {} # 最後に読み込まれた 回 保持
@count = 0 # 全体の読み込み回数
@delete = 100 # 削除対象回数
# ※この回数の間、読み込まれなかったものは、自動放棄。
#-----------------------------------------------------------------------
# ● キャッシュ読み込み
#-----------------------------------------------------------------------
def self.load_bitmap(folder_name, filename, hue = 0)
# 全体の読み込み回数増加
@count += 1
# 元画像のキャッシュ
path = folder_name + filename
if not @cache.include?(path) or @cache[path].disposed?
if filename != ""
@cache[path] = Bitmap.new(path)
else
@cache[path] = Bitmap.new(32, 32)
end
end
# 色相の変換が無い場合、元画像を返す。
if hue == 0
@last_count[path] = @count # 読み込まれた回を更新
@cache[path]
else
# 色相に変化が・る場合のキャッシュ
key = [path, hue]
if not @cache.include?(key) or @cache[key].disposed?
@cache[key] = @cache[path].clone
@cache[key].hue_change(hue)
end
@last_count[key] = @count # 読み込まれた回を更新
@cache[key]
end
end
#-----------------------------------------------------------------------
# ● アニメーション読み込み
#-----------------------------------------------------------------------
def self.animation(filename, hue)
self.load_bitmap("Graphics/Animations/", filename, hue)
end
#-----------------------------------------------------------------------
# ● キャッシュ整理
#-----------------------------------------------------------------------
def self.clear
# 削除対象カウント設定
del_count = @count - @delete
# 削除処理
# @deleteの間、読み込まれなかったアニメのBitmapを放棄します。
# @deleteが0のときは無効。
if @delete > 0
for key in @cache.keys
# まだ放棄されていない場合
if not @cache[key].disposed?
# 削除対象カウントなら放棄
if @last_count[key].to_i <= del_count
@cache[key].dispose
end
end
end
end
end
#-----------------------------------------------------------------------
# ● 全ファイル読み込み
# $game_animationsが初期化された後に呼び出して下さい。
# この機能を使う場合は、
# @deleteを0にするか、多めにしておくことをお勧めします。
#-----------------------------------------------------------------------
def self.preload
for anime in $data_animations
if anime != nil
self.animation(anime.animation_name, anime.animation_hue)
end
end
end
end
end
#-------------------------------------------------------------------------------
# ● RPG::Sprite 再定義
#-------------------------------------------------------------------------------
module RPG
class Sprite < ::Sprite
#------------------------------------------------------------------------
# ● 戦闘アニメーション表示
# 引数:animation 表示アニメーション(Game_Animationクラス)
# hit ヒットフラグ(Boolean)
#------------------------------------------------------------------------
def animation(animation, hit)
# 既にアニメーションがセットされている場合、放棄
dispose_animation
# アニメーション設定
@_animation = animation
# もしアニメーションが空だったら処理終了
return if @_animation == nil
# ヒットフラグ設定
@_animation_hit = hit
# アニメーションタイマーを最大フレーム数で設定
@_animation_duration = @_animation.frame_max
# アニメーション用Bitmap取得
animation_name = @_animation.animation_name
animation_hue = @_animation.animation_hue
# アニメ用キャッシュより、画像読み込み
bitmap = RPG::Cache_Battle.animation(animation_name, animation_hue)
# アニメーション用スプライト初期化
@_animation_sprites = []
# アニメーションが画面表示では無い、またはアニメーションが画面に無い場合
if @_animation.position != 3 or not @@_animations.include?(animation)
# スプライトを新規作成
for i in 0..15
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
@_animation_sprites.push(sprite)
end
# 全体のアニメーション保持用に登録されていない場合、追加
unless @@_animations.include?(animation)
@@_animations.push(animation)
end
end
# アニメーション更新処理実行
update_animation
end
#------------------------------------------------------------------------
# ● 戦闘アニメーション(ループ)開始
#------------------------------------------------------------------------
def loop_animation(animation)
# 既に同じものが登録されているときは何もしない。
return if animation == @_loop_animation
# 一度放棄
dispose_loop_animation
# アニメーション設定
@_loop_animation = animation
# 空なら処理終了
return if @_loop_animation == nil
# アニメーションのコマ数初期化
@_loop_animation_index = 0
# アニメーション用Bitmap作成
animation_name = @_loop_animation.animation_name
animation_hue = @_loop_animation.animation_hue
# アニメ用キャッシュより、画像読み込み
bitmap = RPG::Cache_Battle.animation(animation_name, animation_hue)
# アニメーション用スプライト初期化
@_loop_animation_sprites = []
for i in 0..15
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
@_loop_animation_sprites.push(sprite)
end
# ループアニメ更新
update_loop_animation
end
#------------------------------------------------------------------------
# ● アニメーション放棄処理
#------------------------------------------------------------------------
def dispose_animation
# アニメーション用スプライトが存在するなら放棄
if @_animation_sprites != nil
for sprite in @_animation_sprites
sprite.dispose
end
@_animation_sprites = nil
# アニメーション初期化
@_animation = nil
end
end
#------------------------------------------------------------------------
# ● ループアニメ解放処理
#------------------------------------------------------------------------
def dispose_loop_animation
# ループアニメが存在するなら放棄
if @_loop_animation_sprites != nil
for sprite in @_loop_animation_sprites
sprite.dispose
end
@_loop_animation_sprites = nil
# ループアニメ初期化
@_loop_animation = nil
end
end
end
end
#-------------------------------------------------------------------------------
# ● Scene_Battle 再定義
#-------------------------------------------------------------------------------
class Scene_Battle
#---------------------------------------------------------------------------
# ● main 再定義
#---------------------------------------------------------------------------
alias lite_anime_battle1 main
def main
# 元のmainを通常通り実行
lite_anime_battle1
# 最後にキャッシュを整理する
RPG::Cache_Battle.clear
end
endInformações adicionais
- Categoria: Programação XP
- Adicionado por: LichKing
- Acessos: 46
Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Acesse aqui e saiba como. Obrigado!
