设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2889|回复: 3
打印 上一主题 下一主题

[有事请教] 关于多图层脚本ULDS

[复制链接]

Lv1.梦旅人

梦石
0
星屑
103
在线时间
16 小时
注册时间
2018-1-14
帖子
7
跳转到指定楼层
1
发表于 2018-8-13 01:53:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我用了ULDS之后,插入的图片都会跟着人的视角移动,请问一下要怎么样才能让图片固定住不会动..........

Lv1.梦旅人

梦石
0
星屑
103
在线时间
16 小时
注册时间
2018-1-14
帖子
7
2
 楼主| 发表于 2018-8-13 01:54:50 | 只看该作者
脚本代码如下
  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.    } </ulds>
  51. *
  52. */


  53. void function() {

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

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

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

  73.         // Converts a coordinate on the map to the corresponding coordinate on the screen.
  74.         rx: function(x, scrollRate) {
  75.             if (scrollRate == null) {
  76.                 scrollRate = $gameMap.tileWidth();
  77.             }

  78.             if (scrollRate === 0) {
  79.                 return x;
  80.             } else {
  81.                 return $gameMap.adjustX(x / scrollRate) * scrollRate;
  82.             }
  83.         },

  84.         ry: function(y, scrollRate) {
  85.             if (scrollRate == null) {
  86.                 scrollRate = $gameMap.tileHeight();
  87.             }

  88.             if (scrollRate === 0) {
  89.                 return y;
  90.             } else {
  91.                 return $gameMap.adjustY(y / scrollRate) * scrollRate;
  92.             }
  93.         },

  94.         update: function() {
  95.             ++this.t;
  96.             this._updater(this.t, $gameSwitches, $gameVariables);
  97.         },

  98.         assignSettings: function(settings) {
  99.             var code = '';
  100.             for (var key in settings) {
  101.                 var value = settings[key];
  102.                 if (typeof(value) === 'string') {
  103.                     // this.x = (formula);
  104.                     // this.scale.x = (formula); // key is "scale.x"
  105.                     code += 'this.' + key + ' = (' + value + ');\n';
  106.                 } else {
  107.                     // if key is "scale.x"
  108.                     // keys is ["scale", "x"]
  109.                     var keys = key.split('.');
  110.                     // set key to "x"
  111.                     key = keys.pop();

  112.                     var target = this;
  113.                     keys.forEach(function(k) {
  114.                         if (typeof(target) !== 'object') {
  115.                             target[k] = {};
  116.                         }
  117.                         target = target[k];
  118.                     });

  119.                     target[key] = value;
  120.                 }
  121.             }
  122.             // You may log the code for debugging purpose.
  123.             // console.log(code);
  124.             this._updater = new Function('t', 's', 'v', code);
  125.         }
  126.     };

  127.     // NOT a class constructor
  128.     function ULDS(settings) {
  129.         settings = assign({}, DEFAULT_SETTINGS, settings);
  130.         var spriteClass = settings.loop ? ULDS.TilingSprite : ULDS.Sprite;
  131.         var bitmap = ImageManager.loadBitmap('img/' + settings.path + '/',
  132.             settings.name, settings.hue, settings.smooth);
  133.         var sprite = new spriteClass(bitmap);

  134.         delete settings.path;
  135.         delete settings.name;
  136.         delete settings.loop;
  137.         delete settings.hue;
  138.         delete settings.smooth;

  139.         sprite.assignSettings(settings);

  140.         return sprite;
  141.     }

  142.     ULDS.Sprite = function(bitmap) {
  143.         Sprite.call(this, bitmap);
  144.     };

  145.     ULDS.Sprite.prototype = Object.create(Sprite.prototype);
  146.     ULDS.Sprite.prototype.constructor = ULDS.Sprite;
  147.     assign(ULDS.Sprite.prototype, Helper);

  148.     ULDS.TilingSprite = function(bitmap) {
  149.         TilingSprite.call(this, bitmap);
  150.         bitmap.addLoadListener(function() {
  151.             this.move(0, 0, bitmap.width, bitmap.height);
  152.         }.bind(this));
  153.     };

  154.     ULDS.TilingSprite.prototype = Object.create(TilingSprite.prototype);
  155.     ULDS.TilingSprite.prototype.constructor = ULDS.TilingSprite;
  156.     assign(ULDS.TilingSprite.prototype, Helper);

  157.     Object.defineProperties(ULDS.TilingSprite.prototype, {
  158.         x: {
  159.             get: function() { return -this.origin.x; },
  160.             set: function(x) { this.origin.x = -x; }
  161.         },
  162.         y: {
  163.             get: function() { return -this.origin.y; },
  164.             set: function(y) { this.origin.y = -y; }
  165.         }
  166.     });

  167.     var ct = Spriteset_Map.prototype.createTilemap;
  168.     Spriteset_Map.prototype.createTilemap = function() {
  169.         ct.call(this);
  170.         $dataMap.note.replace(RE, function(_match, settings) {
  171.             var isValid = false;
  172.             try {
  173.                 settings = JSON.parse(settings);
  174.                 isValid = typeof(settings) === 'object';
  175.                 if (!isValid) {
  176.                     throw 'ULDS settings should be an object';
  177.                 }
  178.             } catch (e) {
  179.                 console.error(e);
  180.                 console.log(settings);
  181.             }
  182.             if (isValid) {
  183.                 this._tilemap.addChild(ULDS(settings));
  184.             }
  185.         }.bind(this));
  186.     };
  187. }();
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
103
在线时间
16 小时
注册时间
2018-1-14
帖子
7
3
 楼主| 发表于 2018-8-13 01:55:35 | 只看该作者
我的设置是这样的:
<ulds> {
     "name": "BlueSky",
     "x": 0,
     "y": 0,
     "loop":false
   } </ulds>
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
425
在线时间
78 小时
注册时间
2018-8-4
帖子
187
4
发表于 2018-8-13 15:54:28 | 只看该作者
对不起。是我拿刀捅了你。只是,只是……
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-3 21:25

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表