敵ターゲットウィンドウにHPゲージを表示したものの
倒した敵のHPゲージがそのまま残り続けてしまうため、解決方法をご教示いただきたいです。
作成中のプラグインが下記になります。
コード: 全て選択
(() =>{
"use strict";
//Window_BattleEnemyのdrawItmeメソッドを再定義
const _Window_BattleEnemy_prototype_drawItem = Window_BattleEnemy.prototype.drawItem;
Window_BattleEnemy.prototype.drawItem = function(index) {
_Window_BattleEnemy_prototype_drawItem.apply(this, arguments);
this.createHpGaugeSprite(index);
}
Window_BattleEnemy.prototype.createHpGaugeSprite = function(index){
const rect = this.itemLineRect(index);
//HPゲージを作成、子オブジェクトとして追加
this._hpGaugeSprite = new Sprite_Gauge();
this.addChild(this._hpGaugeSprite);
this._hpGaugeSprite.setup(this._enemies[index], "hp");
//HPゲージのラベルと値を非表示
this._hpGaugeSprite.drawLabel = function(){}
this._hpGaugeSprite.drawValue = function(){}
//HPゲージ位置を変更
this._hpGaugeSprite.x = rect.x;
this._hpGaugeSprite.y = rect.y;
const x = this._hpGaugeSprite.x - 40;
const y = this._hpGaugeSprite.y + 24 + 17;
this._hpGaugeSprite.move(x, y, rect.width, rect.height);
//HPゲージ幅を変更
const _Sprite_Gauge_bitmapWidth = Sprite_Gauge.prototype.bitmapWidth;
Sprite_Gauge.prototype.bitmapWidth = function () {
const isSceneBattle = SceneManager._scene.constructor.name === 'Scene_Battle';
return isSceneBattle ? 430 : _Sprite_Gauge_bitmapWidth.call(this);
};
//文字領域(敵の名前)高さを変更
const _WindowBase_prototype_lineHeight = Window_Base.prototype.lineHeight;
Window_Base.prototype.lineHeight = function() {
_WindowBase_prototype_lineHeight.call(this);
return 52;
};
};
})();
n体いる敵のうち1体を倒した場合、Indexが-1になるため(この場合は 0, 1, 2が 0, 1になるため)
n番目のゲージがそのまま残り続けているものと推測しています。
addchild先をSprite_Enemyにすれば敵画像が消えたらゲージも消えるのでは…?と試行錯誤してはいるのですが
なんとか敵の名前の下にゲージを表示できないものでしょうか。
また、ゲージ幅の変更や文字領域高さの変更は敵選択ウィンドウ表示時のみに限りたいのですが
他のシーンでも影響が出てしまっているため、適用範囲の制限方法についても教えていただけたら幸いです。
本プラグインは、茶の助様が作成・公開されているMV用のHPゲージ表示プラグインを参考にしており
同様の機能を再現しつつ、レイアウトの調整ができるものを作りたいと考えております。
『ターゲットHP表示 - TYA_EnemyHPGauge.js』
http://tyamvplugin.blog.shinobi.jp/mvpl ... 8%E7%A4%BA
以上、お力添えいただきたくよろしくお願いいたします。