/*:
* @plugindesc 区域图层插件
* @author 雪在燃
* v:1.2
* @help
* 区域图层插件
* 使用地图备注编写<xzr_region:on>打开该功能(注,设置为任意都将打开功能,只有删除该行才会关闭功能)
* 以下是一个事例
* <set_regionID_1:["light",234,5]>
* 代表区域1会将img/system/pictures/light展示出来,并且不透明度为234(0~255,数字越低越不透明),z坐标为5(0~10,越高则越高,降低则会被主角或npc遮盖)
*/
(function () {
var old = Spriteset_Map.prototype.createLowerLayer;
Spriteset_Map.prototype.createLowerLayer = function () {
old.call(this);
if ($dataMap.meta.xzr_region) {
this.createShadowEx();
}
};
Spriteset_Map.prototype.createShadowEx = function () {
var data = null;//JSON.parse($dataMap.mate.set_region);
for (var x = 0; x < $gameMap.width() ; x++) {
for (var y = 0; y < $gameMap.height() ; y++) {
var id = $gameMap.regionId(x, y);
if (id != 0) {
if ($dataMap.meta["set_regionID_" + id]) {
data = JSON.parse($dataMap.meta["set_regionID_" + id]);
var _sprite = new Sprite_Shadow(x, y, id, data);
this._tilemap.addChild(_sprite);
}
}
}
}
}
function Sprite_Shadow(x, y, id) {
this.initialize.apply(this, arguments);
}
Sprite_Shadow.prototype = Object.create(Sprite.prototype);
Sprite_Shadow.prototype.constructor = Sprite_Shadow;
Sprite_Shadow.prototype.initialize = function (x, y, id,data) {
Sprite.prototype.initialize.call(this);
this.bitmap = (ImageManager.loadPicture(data[0]));
this.opacity = data[1];
this._dataZ = data[2];
this._cWidth = 0;
this._cHeight = 0;
this._realX = x;
this._realY = y;
this._isReady = false;
this.z = parseInt(id);
}
Sprite_Shadow.prototype.update = function () {
Sprite.prototype.update.call(this);
if (!this._isReady && ImageManager.isReady()) {
this._cWidth = (this.bitmap.width - 48) / 2;
this._cHeight = (this.bitmap.height - 48) / 2;
this._isReady = true;
}
this.updatePosition();
}
Sprite_Shadow.prototype.updatePosition = function ()
{
this.z = this._dataZ;
this.x = this.screenX();
this.y = this.screenY();
}
Sprite_Shadow.prototype.scrolledX = function () {
return $gameMap.adjustX(this._realX - 0.5);
};
Sprite_Shadow.prototype.scrolledY = function () {
return $gameMap.adjustY(this._realY - 1);
};
Sprite_Shadow.prototype.screenX = function () {
var tw = $gameMap.tileWidth();
return Math.round((this.scrolledX() * tw + tw / 2)-this._cWidth);
};
Sprite_Shadow.prototype.screenY = function () {
var th = $gameMap.tileHeight();
return Math.round((this.scrolledY() * th + th)-this._cHeight);
};
})();