搜索附件  
同能RPG制作大师 附件中心 同能RM技术讨论区 RPG Maker MV 讨论区 【RMMV】美化地图专用:Overlay Mapping by 思维伯克 v1.3: Overlay.zip

【RMMV】美化地图专用:Overlay Mapping by 思维伯克 v1.3: Overlay.zip

 

【RMMV】美化地图专用:Overlay Mapping by 思维伯克 v1.3:
(反正也没有人看)因为一些原因重新找出了之前写的代码,修正了一些bug之后更新到了v1.3版。详细请见帖子后半部分的更新log。

在XP/VX/VA中使用遮罩描绘地图上瘾的同学,到了RMMV中没有相关脚本怎么行?于是在MV到货后,捣鼓了几个小时的代码,1.0版本的Overlay Mapping诞生了。

先来张图


具体功能和VA中的Yami Script Ace - Overlay Mapping基本相同,唯一区别在于light和shadow整合成了同一个图层(light),并且所有的图像都必须是png格式(YSA的light和shadow使用图像的加法和减法用jpg实现的)。
由于MV有脚本管理器,所以请将脚本放入工程目录中 js/plugins文件夹后,打开脚本管理器添加该脚本。如下图所示:



开关和变量编号在此设置,在游戏中修改开关为ON即启用对应图层;修改变量的值对应启用第几号图层。
使用方法在脚本的help里有简短说明,可以参考该说明操作。

脚本内容如下:
JAVASCRIPT 代码
  1. //=============================================================================
  2. // Overlay.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc Overlay Mapping script by SWEBOK v1.3
  6. * @author SWEBOK
  7. *
  8. * @param Light Switch
  9. * @desc Turn on/off light layer
  10. * @default 1
  11. *
  12. * @param Parallax Switch
  13. * @desc Turn on/off parallax layer
  14. * @default 2
  15. *
  16. * @param Ground Switch
  17. * @desc Turn on/off ground layer
  18. * @default 3
  19. *
  20. * @param Light Variable
  21. * @desc Switch to another light
  22. * @default 1
  23. *
  24. * @param Parallax Variable
  25. * @desc Switch to another parallax
  26. * @default 2
  27. *
  28. * @param Ground Variable
  29. * @desc Switch to another ground
  30. * @default 3
  31. *
  32. * @help This plugin does not provide plugin commands.
  33. *
  34. * Last Updated: 02/11/2017
  35. *     v1.0 - 10/24/2015 - first release.
  36. *     v1.1 - 10/27/2015 - upper tilemap layer problem solved
  37. *     v1.2 - 07/10/2016 - add map note tag settings, remove load pic error process
  38. *     v1.3 - 02/11/2017 - fixed a problem about ground pic wrong position
  39. *
  40. * This script will automatically load map's overlay by map's note, and a map can have more than
  41. * one image per layer, so you don't have to create two or more map just for day/night or
  42. * when an event occur.
  43. *
  44. * Create a folder in img and name it overlay.
  45. * Put all of your overlay into img/overlay.
  46. * Your overlay file will have the name set in map's note + "-" + Number.
  47. * Number is 1, 2, 3, ... using for Overlay Variables.
  48. *
  49. * Example: img/overlay/ground2-1.png
  50. *
  51. * Map note example:
  52. *        
  53. *                LIGHT = light1
  54. *                PARALLAX = par1
  55. *                GROUND = ground1
  56. *        
  57. *
  58. * when variable are 1, the map loads light1-1.png, par1-1.png, ground1-1.png from overlay folder.
  59. *
  60. * Tips:
  61. * All pictures must be .png
  62. * Do not use "=" in the names of pictures
  63. */
  64. (function(){
  65.         var parameters = PluginManager.parameters('Overlay');
  66.         var lightSwitch = Number(parameters['Light Switch'] || 1);
  67.         var parallaxSwitch = Number(parameters['Parallax Switch'] || 2);
  68.         var groundSwitch = Number(parameters['Ground Switch'] || 3);
  69.         var lightVariable = Number(parameters['Light Variable'] || 1);
  70.         var parallaxVariable = Number(parameters['Parallax Variable'] || 2);
  71.         var groundVariable = Number(parameters['Ground Variable'] || 3);
  72.         Game_Map.prototype.processMapNotetags = function(){
  73.                 var note1 = //i;
  74.                 var note2 = //i;
  75.                 var notedata = $dataMap.note.split(/[\r\n]+/);
  76.                 this.layerNameEval = '';
  77.                 var layerNameEval = false;
  78.                 this._layerName = ['', '', ''];
  79.                 for(var i = 0; i < notedata.length; i++){
  80.                         var line = notedata[i];
  81.                         console.log(line);
  82.                         if(line.match(note1)){
  83.                                 layerNameEval = true;
  84.                         }elseif(line.match(note2)){
  85.                                 layerNameEval = false;
  86.                         }elseif(layerNameEval){
  87.                                 this.layerNameEval = line;
  88.                                 var layerClass = this.layerNameEval.split('=')[0].trim();
  89.                                 var index = 1;
  90.                                 if(index != -1){
  91.                                         switch(layerClass){
  92.                                                 case'LIGHT':
  93.                                                         this._layerName[0] = this.layerNameEval.split('=')[1].trim();
  94.                                                         break;
  95.                                                 case'PARALLAX':
  96.                                                         this._layerName[1] = this.layerNameEval.split('=')[1].trim();
  97.                                                         break;
  98.                                                 case'GROUND':
  99.                                                         this._layerName[2] = this.layerNameEval.split('=')[1].trim();
  100.                                                         break;
  101.                                         }
  102.                                         console.log(this.layerNameEval.split('=')[1].trim());
  103.                                 }
  104.                         }
  105.                 }
  106.         };
  107.         ImageManager.loadOverlay = function(filename, hue){
  108.                 returnthis.loadBitmap('img/overlay/', filename, hue, false);
  109.         };
  110.         Spriteset_Map.prototype.initialize = function(){
  111.                 Spriteset_Base.prototype.initialize.call(this);
  112.                 this.processMapNotetags();
  113.         };
  114.         Spriteset_Map.prototype.createLowerLayer = function(){
  115.                 Spriteset_Base.prototype.createLowerLayer.call(this);
  116.                 this.createParallax();
  117.                 this.createTilemap();
  118.                 this.createOverlayGround();
  119.                 this.createCharacters();
  120.                 this.createOverlayParallax();
  121.                 this.createShadow();
  122.                 this.createOverlayLight();
  123.                 this.createDestination();
  124.                 this.createWeather();
  125.         };
  126.         Spriteset_Map.prototype.update = function(){
  127.                 Spriteset_Base.prototype.update.call(this);
  128.                 this.updateTileset();
  129.                 this.updateParallax();
  130.                 this.updateTilemap();
  131.                 this.updateOverlayGround();
  132.                 this.updateOverlayParallax();
  133.                 this.updateShadow();
  134.                 this.updateOverlayLight();
  135.                 this.updateWeather();
  136.         };
  137.         Spriteset_Map.prototype.processMapNotetags = function(){
  138.                 $gameMap.processMapNotetags();
  139.         };
  140.         Spriteset_Map.prototype.createOverlayGround = function(){
  141.                 this._overlayGround = new TilingSprite();
  142.                 this._overlayGround.move(0, 0, Graphics.width, Graphics.height);
  143.                 // 2017.2.11 create new layer in tilemap for overlay ground, z = 1
  144.                 var groundLayer = new Sprite();
  145.                 this._tilemap.addChild(groundLayer);
  146.                 groundLayer.z = 1;
  147.                 groundLayer.addChild(this._overlayGround);
  148.         };
  149.         Spriteset_Map.prototype.createCharacters = function(){
  150.                 this._characterSprites = [];
  151.                 $gameMap.events().forEach(function(event){
  152.                         this._characterSprites.push(new Sprite_Character(event));
  153.                 }, this);
  154.                 $gameMap.vehicles().forEach(function(vehicle){
  155.                         this._characterSprites.push(new Sprite_Character(vehicle));
  156.                 }, this);
  157.                 $gamePlayer.followers().reverseEach(function(follower){
  158.                         this._characterSprites.push(new Sprite_Character(follower));
  159.                 }, this);
  160.                 this._characterSprites.push(new Sprite_Character($gamePlayer));
  161.                 for(var i = 0; i < this._characterSprites.length; i++){
  162.                         this._tilemap.addChild(this._characterSprites[i]);
  163.                 }
  164.         };
  165.         Spriteset_Map.prototype.createOverlayParallax = function(){
  166.                 this._overlayParallax = new TilingSprite();
  167.                 this._overlayParallax.move(0, 0, Graphics.width, Graphics.height);
  168.                 this._baseSprite.addChild(this._overlayParallax);
  169.         };
  170.         Spriteset_Map.prototype.createOverlayLight = function(){
  171.                 this._overlayLight = new TilingSprite();
  172.                 this._overlayLight.move(0, 0, Graphics.width, Graphics.height);
  173.                 this._baseSprite.addChild(this._overlayLight);
  174.         };
  175.         Spriteset_Map.prototype.updateOverlayGround = function(){
  176.                 var gndSwitch = $gameSwitches.value(groundSwitch);
  177.                 if(gndSwitch){
  178.                         var groundIndex = $gameVariables.value(groundVariable);
  179.                         if(this._overlayGroundName !== $gameMap._layerName[2] + '-' + groundIndex){
  180.                                 this._overlayGroundName = $gameMap._layerName[2] + '-' + groundIndex;
  181.                                 if($gameMap._layerName[2] !== ''){
  182.                                         this._overlayGround.bitmap = ImageManager.loadOverlay(this._overlayGroundName);
  183.                                 }else{
  184.                                         this._overlayGround.bitmap = ImageManager.loadEmptyBitmap();
  185.                                 }
  186.                         }
  187.                         if(this._overlayGround.bitmap){
  188.                                 this._overlayGround.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  189.                                 this._overlayGround.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  190.                         }
  191.                 }
  192.                 else{
  193.                         if(this._overlayGroundName !== ''){
  194.                                 this._overlayGroundName = '';
  195.                                 this._overlayGround.bitmap = ImageManager.loadEmptyBitmap();
  196.                         }
  197.                 }
  198.         };
  199.         Spriteset_Map.prototype.updateOverlayParallax = function(){
  200.                 var parSwitch = $gameSwitches.value(parallaxSwitch);
  201.                 if(parSwitch){
  202.                         var parIndex = $gameVariables.value(parallaxVariable);
  203.                         if(this._overlayParallaxName !== $gameMap._layerName[1] + '-' + parIndex){
  204.                                 this._overlayParallaxName = $gameMap._layerName[1] + '-' + parIndex;
  205.                                 if($gameMap._layerName[1] !== ''){
  206.                                         this._overlayParallax.bitmap = ImageManager.loadOverlay(this._overlayParallaxName);
  207.                                 }else{
  208.                                         this._overlayParallax.bitmap = ImageManager.loadEmptyBitmap();
  209.                                 }
  210.                         }
  211.                         if(this._overlayParallax.bitmap){
  212.                                 this._overlayParallax.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  213.                                 this._overlayParallax.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  214.                         }
  215.                 }
  216.                 else{
  217.                         if(this._overlayParallaxName !== ''){
  218.                                 this._overlayParallaxName = '';
  219.                                 this._overlayParallax.bitmap = ImageManager.loadEmptyBitmap();
  220.                         }
  221.                 }
  222.         };
  223.         Spriteset_Map.prototype.updateOverlayLight = function(){
  224.                 var liSwitch = $gameSwitches.value(lightSwitch);
  225.                 if(liSwitch){
  226.                         var lightIndex = $gameVariables.value(lightVariable);
  227.                         if(this._overlayLightName !== $gameMap._layerName[0] + '-' + lightIndex){
  228.                                 this._overlayLightName = $gameMap._layerName[0] + '-' + lightIndex;
  229.                                 if($gameMap._layerName[0] !== ''){
  230.                                         this._overlayLight.bitmap = ImageManager.loadOverlay(this._overlayLightName);
  231.                                 }else{
  232.                                         this._overlayLight.bitmap = ImageManager.loadEmptyBitmap();
  233.                                 }
  234.                         }
  235.                         if(this._overlayLight.bitmap){
  236.                                 this._overlayLight.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  237.                                 this._overlayLight.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  238.                         }
  239.                 }
  240.                 else{
  241.                         if(this._overlayLightName !== ''){
  242.                                 this._overlayLightName = '';
  243.                                 this._overlayLight.bitmap = ImageManager.loadEmptyBitmap();
  244.                         }
  245.                 }
  246.         };
  247. })();
复制代码


以下链接为JS文件:

以下链接为范例工程:

PS: 1. 为了节省空间,已将所有自带audio和img文件全部删除,请在使用前补齐所有文件。
      2. 范例工程修改了默认字体,如果有显示上的问题请在脚本管理器中关掉。
      3. 该js脚本将load image时缺失文件报错处理改为了显示一个空bitmap,需要还原报错处理的童鞋删除该部分代码即可~
      4. (注意)由于脚本更新到v1.3版本,最好在最新版本MV下新建工程再制作(为了创建PixiJSv4的库文件)。原范例工程不另外上传v1.3版,直接将贴中代码替换overlay.js,再将地图标签设置为该脚本帮助内的example即可。

更新履历:
    - 2015/10/24 v1.0 新规作成
    - 2015/10/27 v1.1 解决人物行走图在星号地形之上的问题。(将人物行走图的创建图层改回tilemap,然后将ground的创建放在tilemap.lowerlayer上)
    - 2016/07/10 v1.2 添加地图标签设置,移除图像错误处理。
    - 2017/02/11 v1.3 解决了ground图形位置错误的问题。另外,使用pixiJSv4的版本的话,图像不会模糊(简单来说就是该更新MV了)。

第一次接触JavaScript,有些东西不太熟悉,如有问题请多多包涵,结合该脚本的使用反馈会进行不定期更新~
             本帖来自P1论坛作者swebok,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=384577  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

GMT+8, 2024-5-20 19:12 , Processed in 0.029233 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部