#ツクルーム › フォーラム › RPGツクールMZ (RPG Maker MZ) › 【解決】バトルシーンでのレベル表示
-
投稿者投稿
-
munokura参加者バトルシーンでのステータスウィンドウ内のカラム数を戦闘人数に合わせて均等幅にしています。
ここにレベルを表示させたく、下記の関数をプラグインに追加しました。const _Window_BattleStatus_drawActorLevel = Window_BattleStatus.prototype.drawActorLevel;
Window_BattleStatus.prototype.drawActorLevel = function (actor, x, y) {
const bitmapWidth = Math.round(128 * 4 / $gameParty.battleMembers().length);
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.levelA, x, y, 48);
this.resetTextColor();
this.drawText(actor.level, x + 84, y, 36, “right”);
};レベルの数値の位置をカラムの幅に合わせて右寄せしたく、
this.drawText(actor.level, x + 84, y, 36, “right”);
を
this.drawText(actor.level, bitmapWidth, y, 36, “right”);
等と変えてみましたが、思い通りに表示されません。
どの様に変更すべきでしょうか?
それとも、全く違う関数を作るべきでしたら、どのような関数を作るべきか教えてください。-
このトピックは
munokuraが8ヶ月、 2週前に変更しました。
ツクールAI君メンバー## バトルシーンでのレベル表示に関する問題
**実現したいこと**
* バトルシーンのステータスウィンドウにレベルを表示
* 戦闘人数に合わせて均等幅に調整されたカラムに、レベル数値を右寄せで表示**試したこと**
* `Window_BattleStatus.prototype.drawActorLevel` 関数をオーバーライド
* レベル数値を描画する `this.drawText` のx座標引数を変更 (`x + 84` から `bitmapWidth` など)**試用プラグイン**
* なし (デフォルトの `Window_BattleStatus` を改変)
**問題点**
* レベル数値が想定した位置に右寄せで表示されない
**不明点**
* `x` の値の算出方法、`bitmapWidth` 以外の適切なx座標値の算出方法
投稿者様、こちらの要約は意図通りでしょうか?不明点が補足・追記いただけると回答が得やすくなると思われます。
—
### 回答
レベル数値の表示位置が正しくない原因は、`bitmapWidth` がウィンドウ全体の幅を表しているのに対し、`this.drawText()` のx座標はウィンドウ左端からの相対位置であるためです。 右寄せを実現するためには、アクターの表示領域の右端のx座標を計算し、そこからレベル表示分の幅を引く必要があります。
以下のように修正してみてください。
“`javascript
Window_BattleStatus.prototype.drawActorLevel = function(actor, x, y) {
const members = $gameParty.battleMembers();
const bitmapWidth = this.width / members.length; // アクター1人分の幅
const levelWidth = this.textWidth(actor.level); // レベル数値の幅
const xOffset = x + bitmapWidth – levelWidth; // レベル数値の右端のx座標
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.levelA, x, y, 48);
this.resetTextColor();
this.drawText(actor.level, xOffset , y, levelWidth, ‘right’); // 幅指定を追加
};
“`変更点:
* `bitmapWidth` の計算をウィンドウ全体幅を戦闘人数で割るように変更。
* `levelWidth` を追加し、レベル数値のピクセル幅を取得。
* `xOffset` を追加し、アクター表示領域の右端から`levelWidth`を引いた値を計算。
* `this.drawText` の第4引数に `levelWidth` を指定することで、右寄せ処理を正しく行えるように修正。—
※閲覧者の皆様、私の回答に問題がありましたら、ご指摘いただけると助かります。
また、解決できた場合、トピックを編集し「トピックを解決済みにする」にチェックを入れてください。
munokura参加者そのままコピーするとsyntax errorになりました。
下記に修正したところ、想定通りに動作しました。Window_BattleStatus.prototype.drawActorLevel = function (actor, x, y) {
const members = $gameParty.battleMembers();
const bitmapWidth = this.width / members.length; // アクター1人分の幅
const levelWidth = this.textWidth(actor.level); // レベル数値の幅
// const xOffset = x + bitmapWidth – levelWidth; // –は特殊文字だったのでマイナスに書き換えた
const xOffset = x + bitmapWidth – levelWidth; // レベル数値の右端のx座標
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.levelA, x, y, 48);
this.resetTextColor();
// this.drawText(actor.level, xOffset, y, levelWidth, ‘right’); // クォーテーションが特殊文字だったので書き換えた
this.drawText(actor.level, xOffset, y, levelWidth, “right”); // 幅指定を追加
}; -
このトピックは
-
投稿者投稿