多图层显示插件
显示多个图层的插件。可以把图片放在屏幕坐标上(跟随屏幕移动),或者放在地图坐标上。可以显示一张图片,或者让一张图片在一个区域内平铺。可以改变图片的透明度和现实顺序。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; } else { DataManager.___simpleOverlay___.simpleOverlayObjList = []; return DataManager.___simpleOverlay___.simpleOverlayObjList; } }; SimpleOverlay.prototype.hasLayer = function(layerName) { var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID(); for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) { if (simpleOverlayObjList.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; 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; 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.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.toUpperCase(); if (action == "ADDLAYER") { if (argsLength == 8) { var layerName = args; if (DataManager.___simpleOverlay___.hasLayer(layerName) == true) return; var simpleOverlayObj = new SimpleOverlayObj(args, args, args, args, args, args, args, "0", "0", "0", "0", "FALSE"); } } else if (action == "ADDTILINGLAYER") { if (argsLength == 12) { var layerName = args; if (DataManager.___simpleOverlay___.hasLayer(layerName) == true) return; var simpleOverlayObj = new SimpleOverlayObj(args, args, args, args, args, args, args, args, args, args, args, "TRUE"); } } else if (action == "CLEAR") { if (argsLength == 2) { var layerName = args; var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID(); for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) { if (simpleOverlayObjList.layerName === layerName) simpleOverlayObjList.delete = true; } } else if (argsLength == 1) { var simpleOverlayObjList = DataManager.___simpleOverlay___.getSimpleOverlayObjListByMapID(); for (var i = simpleOverlayObjList.length - 1; i >= 0; i--) { simpleOverlayObjList.delete = true; } } } };})();复制代码
本帖来自P1论坛作者(^_^),因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=401607若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]