查看: 3134|回复: 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
星屑
13373
在线时间
1525 小时
注册时间
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
星屑
13373
在线时间
1525 小时
注册时间
2020-3-21
回帖
334

MZ评测员极短23获奖

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

[pre lang="javascript" line="1" file="ULDS.js"]//=============================================================================
// ULDS.js
//=============================================================================

/*:
* @plugindesc Unlimited Layer Display System.
* @author taroxd
*
* @param Default Path
* @desc The default path where pictures are stored.
* @default parallaxes
*
* @param Default Z
* @desc The default Z coordinate for sprites.
* @type number
* @decimals 2
* @min -15
* @max 15
* @default 0.5
*
* @help This plugin does not provide plugin commands.
*
* Map Note: <ulds> JSON </ulds>
* "name": picture filename
* "path": picture path (default to Default Path)
* "loop": true/false
*    Whether the picture should loop.
* "hue"/"smooth": the attribute of a Bitmap.
* <attribute>: the attribute of a Sprite.
*
* A string can be used as a value to be interpreted as a formula.
* In the formula, 't' refers to frame count.
*                 's' refers to $gameSwitches.
*                 'v' refers to $gameVaribles.
*
* Also, various helpers are available, defined in Helper.
*
* If a string is used as a formula of the attribute,
* the attribute will be updated every frame.
*
* By the way, attributes such as "anchor.x" is also available.
*
*
* Here is an example:
*
   <ulds> {
     "name": "BlueSky",
     "x": "this.rx(t)",
     "y": 50,
     "loop": true,
     "opacity": this.rx(v)
   } </ulds>
*
*/


void function() {

    var assign = Object.assign || function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments;
            for (var key in source) {
                target[key] = source[key];
            }
        }
        return target;
    };

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

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

        go: function(s,min,max,time) {
                if (this.godata==null) this.godata=[min,max,time,(max-min)/time,0];
                if (this.rem==null) {this.rem=false;return min;}
                if ($gameSwitches.value(s)!=this.rem) {
                        this.rem=$gameSwitches.value(s);
                        this.godata[4]=time;
                }
                if (this.godata[4]>0)  {
                        this.godata[4]--;
                        return this.rem? this.opacity+this.godata[3]:this.opacity-this.godata[3];
                }
                return this.opacity;
        },

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

            if (scrollRate === 0) {
                return x;
            } else {
                return $gameMap.adjustX(x / scrollRate) * scrollRate;
            }
        },

        ry: function(y, scrollRate) {
            if (scrollRate == null) {
                scrollRate = $gameMap.tileHeight();
            }
            
            if (scrollRate === 0) {
                return y;
            } else {
                return $gameMap.adjustY(y / scrollRate) * scrollRate;
            }
        },

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

        assignSettings: function(settings) {
            var code = '';
            for (var key in settings) {
                var value = settings[key];
                if (typeof(value) === 'string') {
                    // this.x = (formula);
                    // this.scale.x = (formula); // key is "scale.x"
                    code += 'this.' + key + ' = (' + value + ');\n';
                } else {
                    // if key is "scale.x"
                    // keys is ["scale", "x"]
                    var keys = key.split('.');
                    // set key to "x"
                    key = keys.pop();

                    var target = this;
                    keys.forEach(function(k) {
                        if (typeof(target) !== 'object') {
                            target[k] = {};
                        }
                        target = target[k];
                    });

                    target[key] = value;
                }
            }
            // You may log the code for debugging purpose.
            // console.log(code);
            this._updater = new Function('t', 's', 'v', code) ;
        }
    };

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

        delete settings.path;
        delete settings.name;
        delete settings.loop;
        delete settings.hue;
        delete settings.smooth;

        sprite.assignSettings(settings);

        return sprite;
    }

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

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

    ULDS.TilingSprite = function(bitmap) {
        TilingSprite.call(this, bitmap);
        bitmap.addLoadListener(function() {
            this.move(0, 0, bitmap.width, bitmap.height);
        }.bind(this));
    };

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

    Object.defineProperties(ULDS.TilingSprite.prototype, {
        x: {
            get: function() { return -this.origin.x; },
            set: function(x) { this.origin.x = -x; }
        },
        y: {
            get: function() { return -this.origin.y; },
            set: function(y) { this.origin.y = -y; }
        }
    });

    var ct = Spriteset_Map.prototype.createTilemap;
    Spriteset_Map.prototype.createTilemap = function() {
        ct.call(this);
        $dataMap.note.replace(RE, function(_match, settings) {
            var isValid = false;
            try {
                settings = JSON.parse(settings);
                isValid = typeof(settings) === 'object';
                if (!isValid) {
                    throw 'ULDS settings should be an object';
                }
            } catch (e) {
                console.error(e);
                console.log(settings);
            }
            if (isValid) {
                this._tilemap.addChild(ULDS(settings));
            }
        }.bind(this));
    };
}();[/pre]
我添加了一个函数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.

在本版发帖返回顶部