#◆◇◆◇◆ 開発者用・高速数字描写機構 ver 1.13 ◇◆◇◆◇ # サポート掲示板 http://www2.ezbbs.net/21/minto-aaa/ # by みんと =begin 更新履歴 ver 1.13(2009/05/09) XP、VX共用化に関するミスを修正 ver 1.12(2009/03/26) XP、VX共用化に関するミスを修正 ver 1.11(2009/01/25) 後期RGSS用に仕様を変更 ver 1.10 一部のメソッドを修正、及び追加 説明 XPに初期導入されている Bitmap の draw_text は 処理が重く過度のリフレッシュには非情に適していません。 (この処理には時間がかかるため、 1 フレームごとに文字列を再描画するような使い方は推奨されません。) なのでXPゲームにとって恐らく最も多く更新と思われる 「数値」の描写に特化したクラスです。 このクラスで生成された数値の表示は1フレームごとに描写しても FPSの消費が実質0で済み、非情に高速です。 ただし、このRGSSスクリプトは開発者用なので、 使いこなすには「ある程度」のRGSS知識が求められます。 詳しい使い方は 公開中のアクティブレベルアップか、 アクティブバトルステータスを参照してくっださい。 Mint_Picture_Number のプロトタイプが実際に使用されています。 ☆ 以下、開発者様向けの説明 ┏━━━━ クラスメソッド ※()内部は省略可能な引数 ━━━━━━━━━━━━━ ┃ ┃ Mint_Picture_Number.new(x, y, index, (z, size, text)) ┃ ┠────────────────────────────────────── ┃ ┃ index : 描写可能な桁数です。(10000桁なら5) ┃ ┃ z : Z座標です。省略した場合は999になります。 ┃ ┃ size : 1カラーの高さです。 ┃ カラーとは読み込んだ画像をsizeで割った内の1つです。 ┃ 読み込んだ画像を size で割った数がカラーの数になります。 ┃ なので、画像はこの数値で割り切れる必要があります。 ┃ ┃ text : 読み込む画像です。 ┃ 省略した場合はString02というピクチャーを参照します。 ┃ 1つ1つの数字は必ず均等幅で並べる必要があります。 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┏━━━━ メソッド ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┃ ┃ dispose ┃ clear ┃ update ┃ string_pop(picture) ┃ set_text(number, (collar)) ┃ ┠────────────────────────────────────── ┃ ┃ dispose : このクラスで生成されたオブジェクトを解放します。 ┃ 原則的に $scene が変わる前に実行する必要があります。 ┃ ┃ clear : 表示中のピクチャーを削除します。 ┃ ただし、string_pop で生成されたピクチャーは除きます。 ┃ ┃ update : string_pop で表示したピクチャーのスライドを進めます。 ┃ 原則として1フレームに1度呼び出す必要があります。 ┃ ┃ string_pop : pictureで指定した名前のピクチャーを ┃ ピクチャーフォルダから参照してポップします。 ┃ ピクチャーが存在しない場合はエラー落ちします。 ┃ また、このメソッドは処理が重いため、 ┃ 過度の使用はオススメできますん。 ┃ ┃ set_text : number で指定した数字を描写します。 ┃ collar で色を変更できますが、 ┃ size で複数のカラーを用意しておく必要があります。 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┏━━━━ プロパティ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┃ ┃ visible ┃ contents_opacity ┃ ┠────────────────────────────────────── ┃ ┃ visible : 可視状態を変更します。真の時に可視状態になります。 ┃ ┃ contents_opacity : ピクチャーの透明度を変更します。 ┃ ただし、string_pop で生成されたピクチャーは除きます。 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ =end #============================================================================== # ■ Mint_Picture_Number #------------------------------------------------------------------------------ #  ピクチャー数字のスプライト表示を扱うクラスです。 # このクラスは数値の高速再描写に特化したクラスとなっています。 #============================================================================== class Mint_Picture_Number #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :x # X座標 attr_accessor :y # Y座標 attr_reader :visible # 可視状態 attr_reader :string_pop_duration # ストリングポップカウント attr_accessor :string # 文字列のピクチャー attr_reader :contents_opacity # 内容の透明度 attr_accessor :new_number # 演出用の現在値 attr_accessor :after_number # 計算用の現在値 #-------------------------------------------------------------------------- # ● オブジェクト初期化 # x : X座標 # y : Y座標 # index : 求められた行数 # z : Z座標 # size : 求められた1カラーの高さ # text : 求められたピクチャー #-------------------------------------------------------------------------- def initialize(x, y, index, z = 999, size = 24, text = "String02") # ピクチャーデータを読み込んで代入 if Scene_Menu.method_defined?("snapshot_for_background") then @number = Cache.picture(text) else @number = RPG::Cache.picture(text) end # 各種データを初期化 @x = x @y = y @index = index @string_pop_sprite = [] @string_pop_duration = [] @before_number = 0 @after_number = 0 @new_number = 0 @gap_number = 0 @max_number = 0 @refresh_duration = 0 # カラーサイズを取得(画像の高さをsizeで割った数) @collar_size = @number.rect.height / size # 読み込んだ画像の幅を10で割った値が、1文字1文字の幅になる @width = @number.rect.width / 10.0 # 読み込んだ画像の高さをカラーサイズで割った数が1カラーの高さになる @height = @number.rect.height / @collar_size # スプライトを収納する配列を定義 @sprite = [] # スプライト生成(求められた行数分) for i in 0...@index @sprite[i] = Sprite.new @sprite[i].x = x.to_i + (i * @width) @sprite[i].y = y.to_i @sprite[i].z = z @sprite[i].bitmap = @number @sprite[i].visible = false end end #-------------------------------------------------------------------------- # ● Y座標の変更 # n : 新しいY座標 #-------------------------------------------------------------------------- def y=(n) # Y座標の変更(イテレータ) (0...@index).each{|i| @sprite[i].y = n} end #-------------------------------------------------------------------------- # ● 内容の可視状態の変更 # flag : 新しい可視状態 #-------------------------------------------------------------------------- def visible=(flag) # 可視状態の変更(イテレータ) (0...@index).each{|i| @sprite[i].visible = flag} end #-------------------------------------------------------------------------- # ● 内容の透明度の変更 # opacity : 新しい透明度 #-------------------------------------------------------------------------- def contents_opacity=(opacity) # 透明度の変更(イテレータ) (0...@index).each{|i| @sprite[i].opacity = opacity} end #-------------------------------------------------------------------------- # ● クリア #-------------------------------------------------------------------------- def clear # 求められた行数分のビットマップをクリア for i in 0...@index do @sprite[i].bitmap = nil end end #-------------------------------------------------------------------------- # ● 色の判定 #-------------------------------------------------------------------------- def set_color # 色の判定(満タンの場合) if @new_number == @max_number c = 1 # 最終値が最大値の4分の一以下の場合 elsif @new_number <= @max_number / 4 c = 2 # 最終値が最大値の2分の一以下の場合 elsif @new_number <= @max_number / 2 c = 3 # それ以外の場合 else c = 0 end # カラーIDを返す return c end #-------------------------------------------------------------------------- # ● リフレッシュ # number : 現在の値 # max_number : 最大値 #-------------------------------------------------------------------------- def refresh(number, max_number = 0) # 最終値を更新 @before_number = @new_number # 現在値を更新 @after_number = number # 最大値を更新 @max_number = max_number # 最終値と現在値の差を求める gap = @before_number - @after_number # 差分の絶対値が 40 超の場合 if gap.abs > 40 # 差分を 40 で割った余りを引く @new_number -= gap % 40 # 差分がマイナスの場合 if gap <= -1 # 差分値に最終値を代入 @gap_number = @before_number # 差分値が最新値以上になるまで繰り返す while @gap_number >= @new_number # 差分を差分の絶対値で割った値を引く @new_number -= gap / [gap.abs, 40].min end end end end #-------------------------------------------------------------------------- # ● アクティブリフレッシュ #-------------------------------------------------------------------------- def active_refresh # 現在値を最新値が異なる場合 if @after_number != @new_number # 最終値と現在値の差を求める gap = @before_number - @after_number # 差分を差分の絶対値で割った数で最終値を引く @new_number -= gap / [gap.abs, 40].min # 最新値を描写 set_text(@new_number, set_color) # 現在値と最新値が同じ場合 else # HPの現在の値を描写 set_text(@after_number, set_color) # 最終値に現在値を代入 @before_number = @after_number @new_number = @after_number end end #-------------------------------------------------------------------------- # ● セットテキスト # number : 求められた数値 # collar : 求められたカラーインデックス #-------------------------------------------------------------------------- def set_text(number, collar = 0) # 求められた文字を一文字ずつ配列にする text = number.to_s.split(//) # クリア行数 clear_index = text.size == 1 ? 1 : 0 # X座標を調整する x_size = @index - text.size # 求められた行数分繰り返す for i in 0...@index # クリア行数が0で求められた数字が0か、 # 元の数字が存在しなければなら次へ if clear_index == 0 and text[i].to_i == 0 or text[i] == nil @sprite[i].visible = false next end # スプライトを可視状態にする @sprite[i].visible = true # 描写範囲を取得 rect = Rect.new(text[i].to_i * @width, collar * @height, @width, @height) # X座標を調整する(右寄せ) @sprite[i].x = @x.to_i + (i * @width) + (x_size * @width) # 条件をクリアしていれば、クリア行数に1を加算 clear_index += 1 # 条件をクリアしていれば描写 @sprite[i].src_rect = rect end end #-------------------------------------------------------------------------- # ● ストリングポップ # string : 求められた文字列のピクチャーの名前 # x_plus : 外部からのX座標の調整用 # y_plus : 外部からのY座標の調整用 #-------------------------------------------------------------------------- def string_pop(string = "", x_plus = 0, y_plus = 0) # string が無効なら処理を終了 return if string == "" # 配列の nil をなくす @string_pop_sprite.compact! @string_pop_duration.compact! # スプライトを生成 string_pop_sprite = Sprite.new # 画像を描写 if Scene_Menu.method_defined?("snapshot_for_background") then string_pop_sprite.bitmap = Cache.picture(string) else string_pop_sprite.bitmap = RPG::Cache.picture(string) end # 座標データを代入 string_pop_sprite.x = @x.to_i + x_plus string_pop_sprite.y = @y.to_i + y_plus string_pop_sprite.z = 10001 # 配列の先頭にシフト @string_pop_sprite.unshift(string_pop_sprite) @string_pop_duration.unshift(40) end #-------------------------------------------------------------------------- # ● ストリングポップ解放 # index : 求められたインデックス #-------------------------------------------------------------------------- def dispose_string_pop(index = nil) # インデックスが nil なら処理を中断 if index == nil return end # インデックスが -1 なら全て解放する if index == -1 # for 文を使って1つずつ処理 for id in 0...@string_pop_sprite.size # IDが0以上でそこにスプライトが存在すれば解放 if id >= 0 && @string_pop_sprite[id] @string_pop_sprite[id].bitmap.dispose @string_pop_sprite[id].dispose @string_pop_sprite[id] = nil @string_pop_duration[id] = nil end end else # インデックスが0以上でそこにスプライトが存在すれば解放 if index >= 0 && @string_pop_sprite[index] @string_pop_sprite[index].bitmap.dispose @string_pop_sprite[index].dispose @string_pop_sprite[index] = nil @string_pop_duration[index] = nil end end end #-------------------------------------------------------------------------- # ● フレーム更新 # battler : バトラー #-------------------------------------------------------------------------- def update(battler = nil) # 1つでもストリングポップが表示中の場合 if @string_pop_sprite.size > 0 # 表示中のストリングポップを1つずつ処理する for i in 0...@string_pop_sprite.size # ストリングポップを代入 string = @string_pop_sprite[i] # カウントが0の場合 if @string_pop_duration[i] == 0 # ストリングポップを解放 dispose_string_pop(i) # 次の処理へ next end # カウントを減らす @string_pop_duration[i] -= 1 # 残りカウントに応じて分岐 case @string_pop_duration[i] when 36..39 string.y -= 4 when 33..37 string.y -= 2 when 32..34 string.y += 2 when 25..32 string.y += 4 end # 透明度をカウントに応じて下げる string.opacity = 256 - (12 - @string_pop_duration[i]) * 32 end # 配列の nil を無くす @string_pop_sprite.compact! @string_pop_duration.compact! end end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose # スプライトを解放 for s in @sprite s.dispose s = nil end # ストリングポップを全て解放 dispose_string_pop(-1) end end