查看: 46527|回复: 56

[原创发布] 【RMMV】美化地图专用:Overlay Mapping by 思维伯克 v1.3

[复制链接]
梦石
0
星屑
632
在线时间
464 小时
注册时间
2011-4-4
回帖
54
发表于 2015-10-24 22:28:57 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 swebok 于 2017-2-11 23:52 编辑

(反正也没有人看)因为一些原因重新找出了之前写的代码,修正了一些bug之后更新到了v1.3版。详细请见帖子后半部分的更新log。

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

先来张图
QQ截图20151024215910.png

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

QQ截图20151024220001.png

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

脚本内容如下:
  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. *        <OVERLAY>
  53. *                LIGHT = light1
  54. *                PARALLAX = par1
  55. *                GROUND = ground1
  56. *        </OVERLAY>
  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.        
  73.         Game_Map.prototype.processMapNotetags = function () {
  74.                 var note1 = /<(?:OVERLAY)>/i;
  75.                 var note2 = /<\/(?:OVERLAY)>/i;

  76.                 var notedata = $dataMap.note.split(/[\r\n]+/);

  77.                 this.layerNameEval = '';
  78.                 var layerNameEval = false;
  79.                 this._layerName = ['', '', ''];


  80.                 for (var i = 0; i < notedata.length; i++) {
  81.                         var line = notedata[i];
  82.                         console.log(line);
  83.                         if (line.match(note1)) {
  84.                                 layerNameEval = true;
  85.                         } else if (line.match(note2)) {
  86.                                 layerNameEval = false;
  87.                         } else if (layerNameEval) {
  88.                                 this.layerNameEval = line;
  89.                                 var layerClass = this.layerNameEval.split('=')[0].trim();
  90.                                 var index = 1;
  91.                                 if (index != -1) {
  92.                                         switch (layerClass) {
  93.                                                 case 'LIGHT':
  94.                                                         this._layerName[0] = this.layerNameEval.split('=')[1].trim();
  95.                                                         break;
  96.                                                 case 'PARALLAX':
  97.                                                         this._layerName[1] = this.layerNameEval.split('=')[1].trim();
  98.                                                         break;
  99.                                                 case 'GROUND':
  100.                                                         this._layerName[2] = this.layerNameEval.split('=')[1].trim();
  101.                                                         break;
  102.                                         }
  103.                                         console.log(this.layerNameEval.split('=')[1].trim());
  104.                                 }
  105.                         }
  106.                 }
  107.         };

  108.         ImageManager.loadOverlay = function(filename, hue) {
  109.                 return this.loadBitmap('img/overlay/', filename, hue, false);
  110.         };
  111.        
  112.         Spriteset_Map.prototype.initialize = function() {
  113.                 Spriteset_Base.prototype.initialize.call(this);
  114.                 this.processMapNotetags();
  115.         };
  116.        
  117.         Spriteset_Map.prototype.createLowerLayer = function() {
  118.                 Spriteset_Base.prototype.createLowerLayer.call(this);
  119.                 this.createParallax();
  120.                 this.createTilemap();
  121.                 this.createOverlayGround();
  122.                 this.createCharacters();
  123.                 this.createOverlayParallax();
  124.                 this.createShadow();
  125.                 this.createOverlayLight();
  126.                 this.createDestination();
  127.                 this.createWeather();
  128.         };
  129.        
  130.         Spriteset_Map.prototype.update = function() {
  131.                 Spriteset_Base.prototype.update.call(this);
  132.                 this.updateTileset();
  133.                 this.updateParallax();
  134.                 this.updateTilemap();
  135.                 this.updateOverlayGround();
  136.                 this.updateOverlayParallax();
  137.                 this.updateShadow();
  138.                 this.updateOverlayLight();
  139.                 this.updateWeather();
  140.         };
  141.        
  142.         Spriteset_Map.prototype.processMapNotetags = function() {
  143.                 $gameMap.processMapNotetags();
  144.         };
  145.        
  146.         Spriteset_Map.prototype.createOverlayGround = function() {
  147.                 this._overlayGround = new TilingSprite();
  148.                 this._overlayGround.move(0, 0, Graphics.width, Graphics.height);
  149.                 // 2017.2.11 create new layer in tilemap for overlay ground, z = 1
  150.                 var groundLayer = new Sprite();
  151.                 this._tilemap.addChild(groundLayer);
  152.                 groundLayer.z = 1;
  153.                 groundLayer.addChild(this._overlayGround);
  154.         };
  155.        
  156.         Spriteset_Map.prototype.createCharacters = function() {
  157.                 this._characterSprites = [];
  158.                 $gameMap.events().forEach(function(event) {
  159.                         this._characterSprites.push(new Sprite_Character(event));
  160.                 }, this);
  161.                 $gameMap.vehicles().forEach(function(vehicle) {
  162.                         this._characterSprites.push(new Sprite_Character(vehicle));
  163.                 }, this);
  164.                 $gamePlayer.followers().reverseEach(function(follower) {
  165.                         this._characterSprites.push(new Sprite_Character(follower));
  166.                 }, this);
  167.                 this._characterSprites.push(new Sprite_Character($gamePlayer));
  168.                 for (var i = 0; i < this._characterSprites.length; i++) {
  169.                         this._tilemap.addChild(this._characterSprites[i]);
  170.                 }
  171.         };
  172.        
  173.         Spriteset_Map.prototype.createOverlayParallax = function() {
  174.                 this._overlayParallax = new TilingSprite();
  175.                 this._overlayParallax.move(0, 0, Graphics.width, Graphics.height);
  176.                 this._baseSprite.addChild(this._overlayParallax);
  177.         };
  178.        
  179.         Spriteset_Map.prototype.createOverlayLight = function() {
  180.                 this._overlayLight = new TilingSprite();
  181.                 this._overlayLight.move(0, 0, Graphics.width, Graphics.height);
  182.                 this._baseSprite.addChild(this._overlayLight);
  183.         };
  184.        
  185.        
  186.         Spriteset_Map.prototype.updateOverlayGround = function() {
  187.                 var gndSwitch = $gameSwitches.value(groundSwitch);
  188.                 if (gndSwitch) {
  189.                         var groundIndex = $gameVariables.value(groundVariable);
  190.                         if (this._overlayGroundName !== $gameMap._layerName[2] + '-' + groundIndex) {
  191.                                 this._overlayGroundName = $gameMap._layerName[2] + '-' + groundIndex;
  192.                                 if ($gameMap._layerName[2] !== '') {
  193.                                         this._overlayGround.bitmap = ImageManager.loadOverlay(this._overlayGroundName);
  194.                                 } else {
  195.                                         this._overlayGround.bitmap = ImageManager.loadEmptyBitmap();
  196.                                 }
  197.                         }
  198.                         if (this._overlayGround.bitmap) {
  199.                                 this._overlayGround.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  200.                                 this._overlayGround.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  201.                         }
  202.                 }
  203.                 else {
  204.                         if (this._overlayGroundName !== '') {
  205.                                 this._overlayGroundName = '';
  206.                                 this._overlayGround.bitmap = ImageManager.loadEmptyBitmap();
  207.                         }
  208.                 }
  209.         };
  210.        
  211.         Spriteset_Map.prototype.updateOverlayParallax = function() {
  212.                 var parSwitch = $gameSwitches.value(parallaxSwitch);
  213.                 if (parSwitch) {
  214.                         var parIndex = $gameVariables.value(parallaxVariable);
  215.                         if (this._overlayParallaxName !== $gameMap._layerName[1] + '-' + parIndex) {
  216.                                 this._overlayParallaxName = $gameMap._layerName[1] + '-' + parIndex;
  217.                                 if ($gameMap._layerName[1] !== '') {
  218.                                         this._overlayParallax.bitmap = ImageManager.loadOverlay(this._overlayParallaxName);
  219.                                 } else {
  220.                                         this._overlayParallax.bitmap = ImageManager.loadEmptyBitmap();
  221.                                 }
  222.                         }
  223.                         if (this._overlayParallax.bitmap) {
  224.                                 this._overlayParallax.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  225.                                 this._overlayParallax.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  226.                         }
  227.                 }
  228.                 else {
  229.                         if (this._overlayParallaxName !== '') {
  230.                                 this._overlayParallaxName = '';
  231.                                 this._overlayParallax.bitmap = ImageManager.loadEmptyBitmap();
  232.                         }
  233.                 }
  234.         };
  235.        
  236.         Spriteset_Map.prototype.updateOverlayLight = function() {
  237.                 var liSwitch = $gameSwitches.value(lightSwitch);
  238.                 if (liSwitch) {
  239.                         var lightIndex = $gameVariables.value(lightVariable);
  240.                         if (this._overlayLightName !== $gameMap._layerName[0] + '-' + lightIndex) {
  241.                                 this._overlayLightName = $gameMap._layerName[0] + '-' + lightIndex;
  242.                                 if ($gameMap._layerName[0] !== '') {
  243.                                         this._overlayLight.bitmap = ImageManager.loadOverlay(this._overlayLightName);
  244.                                 } else {
  245.                                         this._overlayLight.bitmap = ImageManager.loadEmptyBitmap();
  246.                                 }
  247.                         }
  248.                         if (this._overlayLight.bitmap) {
  249.                                 this._overlayLight.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
  250.                                 this._overlayLight.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
  251.                         }
  252.                 }
  253.                 else {
  254.                         if (this._overlayLightName !== '') {
  255.                                 this._overlayLightName = '';
  256.                                 this._overlayLight.bitmap = ImageManager.loadEmptyBitmap();
  257.                         }
  258.                 }
  259.         };
  260. })();
复制代码


以下链接为JS文件:
Overlay.zip (1.74 KB, 下载次数: 1221, 售价: 1 星屑)
以下链接为范例工程:
OverlayMappingBySWEBOK_v1_1.zip (2.15 MB, 下载次数: 2276, 售价: 1 星屑)
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,有些东西不太熟悉,如有问题请多多包涵,结合该脚本的使用反馈会进行不定期更新~

评分

参与人数 5星屑 +138 赞 +2 收起 理由
dh149597870 + 1
zhangliyue35 + 1 精品文章
79160475 + 6 认可答案
刺夜之枪 + 66 这么快
鑫晴 + 66 精品文章

查看全部评分


老塞风流史

鼬痴汉

梦石
29
星屑
3401
在线时间
1300 小时
注册时间
2010-4-24
回帖
919

短篇十吟唱者组别亚军开拓者

发表于 2015-10-24 22:33:10 | 显示全部楼层
救命恩人啊!!!
作为ULDS狂魔感受到了世界的爱意……
MV!开坑!

评分

参与人数 1星屑 +6 收起 理由
Password + 6 开坑狂魔233

查看全部评分

回复

使用道具 举报

梦石
0
星屑
632
在线时间
464 小时
注册时间
2011-4-4
回帖
54
 楼主| 发表于 2015-10-24 22:41:34 | 显示全部楼层
FHNBHJ 发表于 2015-10-24 22:33
救命恩人啊!!!
作为ULDS狂魔感受到了世界的爱意……
MV!开坑!

刚刚发现help中有个词没修改成MV的样式,等到下次更新再说吧(抄帮助文字的时候没修改全的锅...)

老塞风流史
回复

使用道具 举报

梦石
0
星屑
858
在线时间
929 小时
注册时间
2006-6-26
回帖
1377
发表于 2015-10-25 11:21:33 | 显示全部楼层
我去,,MV已经发售了??????有中文么?
我是不是可以签名了?
回复

使用道具 举报

梦石
0
星屑
4221
在线时间
1104 小时
注册时间
2008-5-17
回帖
199

开拓者

发表于 2015-10-25 19:55:27 | 显示全部楼层
swebok 发表于 2015-10-24 22:41
刚刚发现help中有个词没修改成MV的样式,等到下次更新再说吧(抄帮助文字的时候没修改全的锅...) ...

插件很美 树更美  能伸手不

点评

私信个联系方式  发表于 2015-10-27 20:37
回复

使用道具 举报

永夜蟄居の玖瀨

梦石
0
星屑
71
在线时间
1018 小时
注册时间
2011-9-5
回帖
2707

开拓者贵宾

发表于 2015-10-26 19:10:41 | 显示全部楼层
发现打开菜单后光效就会消失,之后怎么改变变量开关都没有效果……

回复

使用道具 举报

梦石
0
星屑
632
在线时间
464 小时
注册时间
2011-4-4
回帖
54
 楼主| 发表于 2015-10-26 19:53:56 | 显示全部楼层
千葉玖濑 发表于 2015-10-26 19:10
发现打开菜单后光效就会消失,之后怎么改变变量开关都没有效果……

刚才我测试了一下并没有发现这样的问题,请问一下您是如何操作的?还有同时使用了哪些脚本?

点评

哦,原来如此  发表于 2015-10-26 21:49
是我犯蠢了…原来在变量改变的时候光效暂时不会改变。…结果我打开菜单后就因为变量已经改变了,从而导致了光效消失嗯…  发表于 2015-10-26 21:15

老塞风流史
回复

使用道具 举报

梦石
0
星屑
3682
在线时间
4468 小时
注册时间
2008-6-12
回帖
776
发表于 2015-10-27 19:10:18 | 显示全部楼层
报个错误,使用该脚本后星号地形会出现问题,主角永远在最上层

点评

我检查了一下代码,发现问题所在了,将会更新代码。感谢提出问题!  发表于 2015-10-27 20:23
本人三无老人,请大神轻拍
回复

使用道具 举报

梦石
0
星屑
65
在线时间
145 小时
注册时间
2008-2-20
回帖
12
发表于 2016-1-11 03:26:50 | 显示全部楼层
感谢分享。看到外站也有差不多的玩意http://forums.rpgmakerweb.com/in ... allaxground-layers/
(不过不懂鸟语真是蛋疼
(树木的素材是来自VS的吗。为什么我找不到。求给一份
回复

使用道具 举报

梦石
0
星屑
50
在线时间
34 小时
注册时间
2016-1-7
回帖
56
发表于 2016-1-12 13:45:35 | 显示全部楼层
好插件啊
..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部