Project1
标题:
多图层显示插件
[打印本页]
作者:
(^_^)
时间:
2017-7-12 09:38
标题:
多图层显示插件
显示多个图层的插件。可以把图片放在屏幕坐标上(跟随屏幕移动),或者放在地图坐标上。可以显示一张图片,或者让一张图片在一个区域内平铺。可以改变图片的透明度和现实顺序。
SimpleOverlay AddLayer layerName imageFileName isBindToScreen zIndex opacity xPosition yPosition
eg. SimpleOverlay AddLayer layer1 Fog false 11 100 0 0
显示图片。
图层名:layer1
图片名:Fog
是否使用屏幕坐标:不
显示优先度:11 (可以自己尝试-1到11之间的任何值。一般来说11是最上面。)
x坐标:0
y坐标: 0
SimpleOverlay AddTilingLayer layerName imageFileName isBindToScreen zIndex opacity xPosition yPosition width height xMovement yMovement
在区域内平铺图片。
width和height是区域长宽。
xMovement和yMovement是动画速度。
SimpleOverlay Clear
删除地图的全部图层
SimpleOverlay Clear layerName
删除名为“layerName”的图层
图层设置会和地图一起绑定保存,每个图层只要在一张地图上添加一次就行了。
/*:
* @plugindesc Display image layers on screen. Version: 1.0
* @author Rui
* @help
* ----------------------------------------
* SimpleOverlay AddLayer layerName imageFileName isBindToScreen zIndex opacity xPosition yPosition
* ----------------------------------------
* add image layer. layers are saved with map, only need to add once per map. place images in parallaxes folder.
* isBindToScreen: if set to "true", image will stay on screen.
* xPosition/yPosition: top-left position of layer.
* zIndex: if set to "-1", layer is below everything else. if set to 10 or above, layer is above everything else.
* opacity: 0-255
* eg. SimpleOverlay AddLayer layer1 Fog false 11 100 0 0
*
*
* ----------------------------------------
* SimpleOverlay AddTilingLayer layerName imageFileName isBindToScreen zIndex opacity xPosition yPosition width height xMovement yMovement
* ----------------------------------------
* add image layer. layers are saved with map, only need to add once per map. place images in parallaxes folder.
* isBindToScreen: if set to "true", image will stay in screen position.
* xPosition/yPosition: top-left position of layer.
* width/height: width and height of layer
* xMovement/yMovement: animating layer
* zIndex: if set to "-1", layer is below everything else. if set to 10 or above, layer is above everything else.
* opacity: 0-255
* eg. SimpleOverlay AddTilingLayer Fog sunlight true 11 100 0 0 800 800 1 0
*
*
* ----------------------------------------
* SimpleOverlay Clear
* ----------------------------------------
* clear all layers on this map
*
*
* ----------------------------------------
* SimpleOverlay Clear layerName
* ----------------------------------------
* clear layer with layerName
*
*
* License: Free for non-commercial and commercial use
*/
(function() {
//SimpleOverlayObj
function SimpleOverlay() {
this.simpleOverlayObjList = {}; //dictionary with mapID as key
}
SimpleOverlay.prototype.getSimpleOverlayObjListByMapID = function() {
var mapID = $gameMap.mapId().toString();
if (DataManager.___simpleOverlay___.simpleOverlayObjList.hasOwnProperty(mapID)) {
return DataManager.___simpleOverlay___.simpleOverlayObjList[mapID];
}
else {
DataManager.___simpleOverlay___.simpleOverlayObjList[mapID] = [];
return DataManager.___simpleOverlay___.simpleOverlayObjList[mapID];
}
};
SimpleOverlay.prototype.hasLayer = function(layerName) {
var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID();
for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) {
if (simpleOverlayObjList[i].layerName === layerName)
return true;
}
return false;
}
//SimpleOverlayObj object
function SimpleOverlayObj(layerName, imageFileName, isBindToScreen, zIndex, opacity, xPosition, yPosition, width, height, xMovement, yMovement, isTiling) {
this.layerName = layerName;
this.imageFileName = imageFileName;
this.isBindToScreen = isBindToScreen.toUpperCase() === "TRUE";
this.zIndex = parseInt(zIndex);
this.opacity = parseInt(opacity);
this.xPosition = parseInt(xPosition);
this.yPosition = parseInt(yPosition);
this.width = parseInt(width);
this.height = parseInt(height);
this.xMovement = parseInt(xMovement);
this.xMovement *= -1;
this.yMovement = parseInt(yMovement);
this.isTiling = isTiling.toUpperCase() === "TRUE";
this.delete = false;
DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID().push(this);
}
//add sprite when creating text or starting scene
SimpleOverlayObj.prototype.addSprite = function(spriteset_Map, x, y) {
if (this.isTiling == false) {
var sprite = new Sprite();
sprite.anchor.x = 0;
sprite.anchor.y = 0;
sprite.z = this.zIndex;
sprite.opacity = this.opacity;
sprite.bitmap = ImageManager.loadParallax(this.imageFileName);
sprite.___simpleOverlayObjRef___ = this;
spriteset_Map._tilemap.addChild(sprite);
sprite.x = x;
sprite.y = y;
}
else {
var sprite = new TilingSprite();
sprite.anchor.x = 0;
sprite.anchor.y = 0;
sprite.z = this.zIndex;
sprite.opacity = this.opacity;
sprite.bitmap = ImageManager.loadParallax(this.imageFileName);
sprite.___simpleOverlayObjRef___ = this;
spriteset_Map._tilemap.addChild(sprite);
sprite.move(x, y, this.width, this.height);
}
};
//update function
SimpleOverlayObj.prototype.update = function(index, spriteset_Map) {
var foundSprite = false;
var child = null;
for (var i = spriteset_Map._tilemap.children.length - 1; i >= 0; i--) {
child = spriteset_Map._tilemap.children[i];
if (typeof(child.___simpleOverlayObjRef___)==='undefined') {
continue;
}
else {
if (child.___simpleOverlayObjRef___ == this) {
foundSprite = true;
if (this.delete == true) {
child.bitmap = null;
spriteset_Map._tilemap.removeChildAt(i);
}
break;
}
}
}
if (this.delete == true) {
DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID().splice(index, 1);
return;
}
//get center position
var centerX = this.xPosition;
var centerY = this.yPosition;
if (this.isBindToScreen == false) {
var tw = $gameMap.tileWidth();
var th = $gameMap.tileHeight();
var scrolledX = $gameMap.adjustX(this.xPosition / tw);
var scrolledY = $gameMap.adjustY(this.yPosition / th);
var screenX = Math.round(scrolledX * tw);
var screenY = Math.round(scrolledY * th + th);
centerX = screenX;
centerY = screenY - $gameMap.tileHeight();
}
//update sprite position
if (foundSprite == false) {
child = this.addSprite(spriteset_Map, centerX, centerY);
}
else {
if (this.isTiling == false) {
child.x = centerX;
child.y = centerY;
}
else {
child.move(centerX, centerY, this.width, this.height);
child.origin.x += this.xMovement;
child.origin.y += this.yMovement;
}
}
};
//create SimpleOverlay in DataManager
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects.call(this);
if (typeof(DataManager.___simpleOverlay___)==='undefined')
DataManager.___simpleOverlay___ = new SimpleOverlay();
};
//add sprites on createTilemap
var _Spriteset_Map_prototype_createTilemap = Spriteset_Map.prototype.createTilemap;
Spriteset_Map.prototype.createTilemap = function() {
_Spriteset_Map_prototype_createTilemap.call(this);
//remove all layer sprites if exits
for (var i = this._tilemap.children.length - 1; i >= 0; i--) {
var child = this._tilemap.children[i];
if (typeof(child.___simpleOverlayObjRef___)==='undefined') {
continue;
}
else {
child.bitmap = null;
this._tilemap.removeChildAt(i);
}
}
}
//update SimpleOverlayObjList
var _Spriteset_Map_prototype_updateTilemap = Spriteset_Map.prototype.updateTilemap;
Spriteset_Map.prototype.updateTilemap = function() {
_Spriteset_Map_prototype_updateTilemap.call(this);
var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID();
for (var i = simpleOverlayObjList.length - 1; i >= 0; i--)
simpleOverlayObjList[i].update(i, this);
};
//read plugin command
var _Game_Interpreter_prototype_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_prototype_pluginCommand.call(this, command, args);
//only work with Scene_Map
if (SceneManager._scene instanceof Scene_Map == false)
return;
var argsLength = args.length;
var action = args[0].toUpperCase();
if (action == "ADDLAYER") {
if (argsLength == 8) {
var layerName = args[1];
if (DataManager.___simpleOverlay___.hasLayer(layerName) == true)
return;
var simpleOverlayObj = new SimpleOverlayObj(args[1], args[2], args[3], args[4], args[5], args[6], args[7], "0", "0", "0", "0", "FALSE");
}
}
else if (action == "ADDTILINGLAYER") {
if (argsLength == 12) {
var layerName = args[1];
if (DataManager.___simpleOverlay___.hasLayer(layerName) == true)
return;
var simpleOverlayObj = new SimpleOverlayObj(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], "TRUE");
}
}
else if (action == "CLEAR") {
if (argsLength == 2) {
var layerName = args[1];
var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID();
for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) {
if (simpleOverlayObjList[i].layerName === layerName)
simpleOverlayObjList[i].delete = true;
}
}
else if (argsLength == 1) {
var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID();
for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) {
simpleOverlayObjList[i].delete = true;
}
}
}
};
})();
复制代码
作者:
铅笔描绘的思念
时间:
2017-7-12 10:26
本帖最后由 铅笔描绘的思念 于 2017-7-12 10:27 编辑
请勿机翻 关键词都没了
好吧原来不是机翻 排版看得以为备注带中文的。。
作者:
君助
时间:
2017-7-12 10:54
。。。。。。。。。。。。。之前怎么找无限图层插件都找不到合手的,今天悬赏区发了个帖子,突然一下出来了好多图层插件
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1