查看: 3204|回复: 8

[有事请教] ULDS如何实现地图局部消失或出现时产生渐变效果?

[复制链接]
梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
发表于 2021-2-27 22:35:11 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 664145107 于 2021-2-28 14:45 编辑

多亏ULDS插件,做出了一个一直以来很想实现的效果:同一地图内部分区域只有进入时才出现
但是正如图所见进入对应区域时地图是突然出现的,比较生硬,加一个渐变过渡一下就会好很多,所以想问一下该如何实现
4.gif
梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
 楼主| 发表于 2021-2-28 19:25:11 | 显示全部楼层
不要沉呀……
回复

使用道具 举报

梦石
0
星屑
2983
在线时间
299 小时
注册时间
2018-4-6
回帖
316
发表于 2021-2-28 19:51:00 | 显示全部楼层
好像有行指令可以渐变,但是我忘了orz
范例里面应该有写的。
或者那个rgd的灯光脚本也包含有类似的代码。
回复

使用道具 举报

梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
 楼主| 发表于 2021-2-28 19:56:41 | 显示全部楼层
whitedewxiao 发表于 2021-2-28 19:51
好像有行指令可以渐变,但是我忘了orz
范例里面应该有写的。
或者那个rgd的灯光脚本也包含有类似的代码。 ...

淡入淡出吗,那个我试过,是画面转黑再转回,但是这样做的话和切换场景没有区别了
回复

使用道具 举报

梦石
18
星屑
13427
在线时间
1526 小时
注册时间
2020-3-21
回帖
334

MZ评测员极短23获奖

发表于 2021-3-1 00:41:33 | 显示全部楼层
本来写了一大段然后提供了几个办法(依据实际情况),结果因为查别的东西查完后随手关了浏览器而导致没有记录了orz……
所以楼主直接贴出地图备注后直接给楼主最简单的办法吧……(依据你的实现方法来为ulds添加点功能或者直接推荐别的插件)
回复

使用道具 举报

梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
 楼主| 发表于 2021-3-1 20:09:55 | 显示全部楼层
本帖最后由 664145107 于 2021-3-1 20:11 编辑
仇九 发表于 2021-3-1 00:41
本来写了一大段然后提供了几个办法(依据实际情况),结果因为查别的东西查完后随手关了浏览器而导致没有记 ...


<ulds>{
"name":"!0-2-a_",
"visible":"$gameSwitches.value(2)",
"x":"this.rx(0)",
"y":"this.ry(0)",
"z":2,
"opacity":255,
"loop":false
}</ulds>

ulds是按照原本的用法使用的,没有对插件做任何修改(本来想改来着但是看不懂所以无从下手orz
用了不同的开关控制两个部分地图的可见度,然后做两个相邻事件,一个用来开对应开关另一个相反
回复

使用道具 举报

梦石
18
星屑
13427
在线时间
1526 小时
注册时间
2020-3-21
回帖
334

MZ评测员极短23获奖

发表于 2021-3-1 23:10:27 | 显示全部楼层
本帖最后由 仇九 于 2021-3-1 23:14 编辑
  1. //=============================================================================
  2. // ULDS.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc Unlimited Layer Display System.
  6. * @author taroxd
  7. *
  8. * @param Default Path
  9. * @desc The default path where pictures are stored.
  10. * @default parallaxes
  11. *
  12. * @param Default Z
  13. * @desc The default Z coordinate for sprites.
  14. * @type number
  15. * @decimals 2
  16. * @min -15
  17. * @max 15
  18. * @default 0.5
  19. *
  20. * @help This plugin does not provide plugin commands.
  21. *
  22. * Map Note: <ulds> JSON </ulds>
  23. * "name": picture filename
  24. * "path": picture path (default to Default Path)
  25. * "loop": true/false
  26. *    Whether the picture should loop.
  27. * "hue"/"smooth": the attribute of a Bitmap.
  28. * <attribute>: the attribute of a Sprite.
  29. *
  30. * A string can be used as a value to be interpreted as a formula.
  31. * In the formula, 't' refers to frame count.
  32. *                 's' refers to $gameSwitches.
  33. *                 'v' refers to $gameVaribles.
  34. *
  35. * Also, various helpers are available, defined in Helper.
  36. *
  37. * If a string is used as a formula of the attribute,
  38. * the attribute will be updated every frame.
  39. *
  40. * By the way, attributes such as "anchor.x" is also available.
  41. *
  42. *
  43. * Here is an example:
  44. *
  45.    <ulds> {
  46.      "name": "BlueSky",
  47.      "x": "this.rx(t)",
  48.      "y": 50,
  49.      "loop": true,
  50.      "opacity": this.rx(v)
  51.    } </ulds>
  52. *
  53. */


  54. void function() {

  55.     var assign = Object.assign || function(target) {
  56.         for (var i = 1; i < arguments.length; i++) {
  57.             var source = arguments[i];
  58.             for (var key in source) {
  59.                 target[key] = source[key];
  60.             }
  61.         }
  62.         return target;
  63.     };

  64.     var RE = /<ulds>([^]*?)<\/ulds>/ig;
  65.     var parameters = PluginManager.parameters('ULDS');
  66.     var DEFAULT_SETTINGS = {
  67.         z: parseFloat(parameters['Default Z']),
  68.         path: parameters['Default Path'],
  69.         smooth: true
  70.     };

  71.     // Feel free to add your own helper.
  72.     var Helper = {
  73.         t: 0,

  74.         go: function(s,min,max,time) {
  75.                 if (this.godata==null) this.godata=[min,max,time,(max-min)/time,0];
  76.                 if (this.rem==null) {this.rem=false;return min;}
  77.                 if ($gameSwitches.value(s)!=this.rem) {
  78.                         this.rem=$gameSwitches.value(s);
  79.                         this.godata[4]=time;
  80.                 }
  81.                 if (this.godata[4]>0)  {
  82.                         this.godata[4]--;
  83.                         return this.rem? this.opacity+this.godata[3]:this.opacity-this.godata[3];
  84.                 }
  85.                 return this.opacity;
  86.         },

  87.         // Converts a coordinate on the map to the corresponding coordinate on the screen.
  88.         rx: function(x, scrollRate) {
  89.             if (scrollRate == null) {
  90.                 scrollRate = $gameMap.tileWidth();
  91.             }

  92.             if (scrollRate === 0) {
  93.                 return x;
  94.             } else {
  95.                 return $gameMap.adjustX(x / scrollRate) * scrollRate;
  96.             }
  97.         },

  98.         ry: function(y, scrollRate) {
  99.             if (scrollRate == null) {
  100.                 scrollRate = $gameMap.tileHeight();
  101.             }
  102.             
  103.             if (scrollRate === 0) {
  104.                 return y;
  105.             } else {
  106.                 return $gameMap.adjustY(y / scrollRate) * scrollRate;
  107.             }
  108.         },

  109.         update: function() {
  110.             ++this.t;
  111.             this._updater(this.t, $gameSwitches, $gameVariables);
  112.         },

  113.         assignSettings: function(settings) {
  114.             var code = '';
  115.             for (var key in settings) {
  116.                 var value = settings[key];
  117.                 if (typeof(value) === 'string') {
  118.                     // this.x = (formula);
  119.                     // this.scale.x = (formula); // key is "scale.x"
  120.                     code += 'this.' + key + ' = (' + value + ');\n';
  121.                 } else {
  122.                     // if key is "scale.x"
  123.                     // keys is ["scale", "x"]
  124.                     var keys = key.split('.');
  125.                     // set key to "x"
  126.                     key = keys.pop();

  127.                     var target = this;
  128.                     keys.forEach(function(k) {
  129.                         if (typeof(target) !== 'object') {
  130.                             target[k] = {};
  131.                         }
  132.                         target = target[k];
  133.                     });

  134.                     target[key] = value;
  135.                 }
  136.             }
  137.             // You may log the code for debugging purpose.
  138.             // console.log(code);
  139.             this._updater = new Function('t', 's', 'v', code) ;
  140.         }
  141.     };

  142.     // NOT a class constructor
  143.     function ULDS(settings) {
  144.         settings = assign({}, DEFAULT_SETTINGS, settings);
  145.         var spriteClass = settings.loop ? ULDS.TilingSprite : ULDS.Sprite;
  146.         var bitmap = ImageManager.loadBitmap('img/' + settings.path + '/',
  147.             settings.name, settings.hue, settings.smooth);
  148.         var sprite = new spriteClass(bitmap);

  149.         delete settings.path;
  150.         delete settings.name;
  151.         delete settings.loop;
  152.         delete settings.hue;
  153.         delete settings.smooth;

  154.         sprite.assignSettings(settings);

  155.         return sprite;
  156.     }

  157.     ULDS.Sprite = function(bitmap) {
  158.         Sprite.call(this, bitmap);
  159.     };

  160.     ULDS.Sprite.prototype = Object.create(Sprite.prototype);
  161.     ULDS.Sprite.prototype.constructor = ULDS.Sprite;
  162.     assign(ULDS.Sprite.prototype, Helper);

  163.     ULDS.TilingSprite = function(bitmap) {
  164.         TilingSprite.call(this, bitmap);
  165.         bitmap.addLoadListener(function() {
  166.             this.move(0, 0, bitmap.width, bitmap.height);
  167.         }.bind(this));
  168.     };

  169.     ULDS.TilingSprite.prototype = Object.create(TilingSprite.prototype);
  170.     ULDS.TilingSprite.prototype.constructor = ULDS.TilingSprite;
  171.     assign(ULDS.TilingSprite.prototype, Helper);

  172.     Object.defineProperties(ULDS.TilingSprite.prototype, {
  173.         x: {
  174.             get: function() { return -this.origin.x; },
  175.             set: function(x) { this.origin.x = -x; }
  176.         },
  177.         y: {
  178.             get: function() { return -this.origin.y; },
  179.             set: function(y) { this.origin.y = -y; }
  180.         }
  181.     });

  182.     var ct = Spriteset_Map.prototype.createTilemap;
  183.     Spriteset_Map.prototype.createTilemap = function() {
  184.         ct.call(this);
  185.         $dataMap.note.replace(RE, function(_match, settings) {
  186.             var isValid = false;
  187.             try {
  188.                 settings = JSON.parse(settings);
  189.                 isValid = typeof(settings) === 'object';
  190.                 if (!isValid) {
  191.                     throw 'ULDS settings should be an object';
  192.                 }
  193.             } catch (e) {
  194.                 console.error(e);
  195.                 console.log(settings);
  196.             }
  197.             if (isValid) {
  198.                 this._tilemap.addChild(ULDS(settings));
  199.             }
  200.         }.bind(this));
  201.     };
  202. }();
复制代码

我添加了一个函数go,这样使用:
<ulds>{
"name":"!0-2-a_",
"x":"this.rx(0)",
"y":"this.ry(0)",
"z":2,
"opacity":"this.go(2,0,255,60)",
"loop":false
}</ulds>
注意"opacity"后面的内容改了一下,并且删去了visible那一行。
初始图片透明度为0,开关2打开时,图片的透明度会在60帧内从0变到255,关闭开关2时,图片的透明度会在60帧内从255变到0。
this.go(开关id,最初透明度,变化后透明度,变化时间),这个只能用于opacity。
效果:
bandicam 2021-03-01 22-52-26-115[00-00-01--00-00-03].gif
回复

使用道具 举报

梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
 楼主| 发表于 2021-3-2 01:04:49 | 显示全部楼层
本帖最后由 664145107 于 2021-3-2 01:05 编辑
仇九 发表于 2021-3-1 23:10
//=============================================================================
// ULDS.js
//======= ...


卧槽强啊!不过是不是意味着其他的远景图的visible那一条也要删去了呢
以及如果把时间从60改成0是不是就是立即出现图片了呢,如果是的话那似乎确实可以取代visible那条了
回复

使用道具 举报

梦石
0
星屑
1356
在线时间
153 小时
注册时间
2019-5-31
回帖
47
 楼主| 发表于 2021-3-2 16:11:18 | 显示全部楼层
仇九 发表于 2021-3-1 23:10
//=============================================================================
// ULDS.js
//======= ...

不知为何在我的工程里没有效果orz
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部