rpgmaker mv 屏幕左右两侧固定立绘 + 呼吸效果



//=============================================================================
// BustBreathFixedSides.js
//=============================================================================
/*:
* @plugindesc 【屏幕左右两侧固定立绘 + 呼吸效果】坐标自动固定,左右分开管理,地图、对话可用。
* @author ChatGPT
*
* @param breathSpeed
* @text 呼吸速度
* @type number
* @decimals 2
* @default 0.03
*
* @param breathScale
* @text 呼吸幅度
* @type number
* @decimals 2
* @default 0.02
*
* @help
*
* 插件指令:
*
* ShowLeftBust 图片名
* ShowRightBust 图片名
*
* HideLeftBust
* HideRightBust
*
* 图片放 img/pictures/ 不要写.png
* 自动固定左边 / 右边,无需坐标。
*/

(function() {
var parameters = PluginManager.parameters('BustBreathFixedSides');
var breathSpeed = Number(parameters['breathSpeed'] || 0.03);
var breathScale = Number(parameters['breathScale'] || 0.02);

var LeftBustSprite = null;
var RightBustSprite = null;

function createBustSprite(name, side) {
var sprite = new Sprite(ImageManager.loadPicture(name));
sprite.anchor.x = (side === 'right') ? 1 : 0;
sprite.anchor.y = 0;
sprite._breathPhase = 0;
sprite.update = function() {
Sprite.prototype.update.call(this);
this._breathPhase += breathSpeed;
var scale = 1 + Math.sin(this._breathPhase) * breathScale;
this.scale.x = scale;
this.scale.y = scale;
};
updateBustPosition(sprite, side);
return sprite;
}

function updateBustPosition(sprite, side) {
var y = Graphics.boxHeight / 2 - sprite.height / 2;
var x = (side === 'right') ? Graphics.boxWidth : 0;
sprite.x = x;
sprite.y = y;
}

function removeBustSprite(sprite) {
if (sprite && SceneManager._scene) {
SceneManager._scene.removeChild(sprite);
sprite.bitmap = null;
sprite = null;
}
return null;
}

var _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
if (LeftBustSprite) updateBustPosition(LeftBustSprite, 'left');
if (RightBustSprite) updateBustPosition(RightBustSprite, 'right');
};

var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
if (LeftBustSprite) SceneManager._scene.addChild(LeftBustSprite);
if (RightBustSprite) SceneManager._scene.addChild(RightBustSprite);
};

var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (SceneManager._scene) {
switch (command) {
case 'ShowLeftBust':
if (LeftBustSprite) LeftBustSprite = removeBustSprite(LeftBustSprite);
LeftBustSprite = createBustSprite(args[0], 'left');
SceneManager._scene.addChild(LeftBustSprite);
break;
case 'ShowRightBust':
if (RightBustSprite) RightBustSprite = removeBustSprite(RightBustSprite);
RightBustSprite = createBustSprite(args[0], 'right');
SceneManager._scene.addChild(RightBustSprite);
break;
case 'HideLeftBust':
LeftBustSprite = removeBustSprite(LeftBustSprite);
break;
case 'HideRightBust':
RightBustSprite = removeBustSprite(RightBustSprite);
break;
}
}
};
})();

插件指令:
*
* ShowLeftBust 图片名
* ShowRightBust 图片名
*
* HideLeftBust
* HideRightBust
*
* 图片放 img/pictures/ 不要写.png
* 自动固定左边 / 右边,无需坐标。


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注