do-disciplinary-committee-m.../www/js/plugins/MW_AnimationOffset.js
2025-05-04 14:43:03 -05:00

41 lines
No EOL
1.6 KiB
JavaScript

/*:
* @plugindesc 敵キャラごとのアニメーション再生位置にオフセットを加えるプラグイン(表示位置そのものをずらします)@ChatGPT
*
* @help
* 敵キャラのメモ欄に以下のタグを記入してください:
*
* <AnimationOffsetX: -20>
* <AnimationOffsetY: 30>
*
* ※単位はピクセル。正なら右・下方向へずれます。
* ※プラグインコマンドなどはありません。
*/
(function() {
// メモ欄からオフセットを取得
const getEnemyAnimationOffset = function(enemy) {
const note = enemy.enemy().note;
const xMatch = note.match(/<AnimationOffsetX:\s*(-?\d+)>/i);
const yMatch = note.match(/<AnimationOffsetY:\s*(-?\d+)>/i);
const offsetX = xMatch ? Number(xMatch[1]) : 0;
const offsetY = yMatch ? Number(yMatch[1]) : 0;
return [offsetX, offsetY];
};
// Sprite_Enemy用にstartAnimationを拡張
const _Sprite_Enemy_startAnimation = Sprite_Enemy.prototype.startAnimation;
Sprite_Enemy.prototype.startAnimation = function(animation, mirror, delay) {
const sprite = new Sprite_Animation();
sprite.setup(this, animation, mirror, delay);
// 敵のメモ欄にオフセットがあれば適用
if (this._enemy) {
const [offsetX, offsetY] = getEnemyAnimationOffset(this._enemy);
sprite.x += offsetX;
sprite.y += offsetY;
}
this.parent.addChild(sprite);
this._animationSprites.push(sprite);
};
})();