设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 94|回复: 0

[转载发布] Foreground Parallax for MZ (Updated With Lock Parallax Option)

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    4 天前
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4600

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    23207
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28701

    灌水之王

    发表于 4 天前 | 显示全部楼层 |阅读模式
    Years ago, I created a VX Ace script for fog effects, which was a feature that existed on RPG Maker XP but that was absent on VX Ace.  The only time that I have ever shown the script was on the Facebook page for RPG Maker Web, but I have never bothered to post the script on the RPG Maker Forum before and have started to become more involved with the community only lately, especially due to being excited with the release of RPG Maker MZ.  As a result, I improved my fog script for VX Ace and used that as a blueprint for the Foreground Parallax plugin for RPG Maker MV, which would in turn be converted into the Foreground Parallax plugin for RMMZ.  With the backstory out of the way, I will now introduce to you the Foreground Parallax plugin that I created for MZ.  For the record, I'm aware that there are other people that have created their own Foreground Parallax plugins and that one of those plugins came with RMMZ as a launch plugin, but I wanted to be more involved with the RPG Maker/game designer community, which was/is why I created the Foreground Parallax plugin for RMMZ.  The following image is the screenshot of the Plugin Settings that shows the Foreground Parallax plugin as a selected plugin.

    [/url]

    If you look at the Author section, you will notice that I didn't credit myself as the author of the plugin and did so out of my own choice.  I want for this plugin to be an open source plugin as well as a copyleft plugin, so I'm not claiming copyright on the plugin and everyone have full permission to modify the plugin as well as take credit for the plugin if any modification (especially a big modification) was done to it. When I created the fog script for VX Ace and the Foreground Parallax for RMMV, I made sure that they would be accessible through the Script Event Command as I wanted for the Fog/Foreground Parallax to be like an Event Command and part of RMVX Ace/RMMV.  Unlike the previous two versions of the Foreground Parallax code (either as a script or as a plugin), the Foreground Parallax plugin for MZ is accessible through the Plugin Command Event Command.  I wanted to take full advantage of the improvement on the Plugin Command for RMMZ and make the plugin accessible to everyone, so there would be no need to use a script line to activate/deactivate the foreground parallax (which could/would also lead to error(s) if the line of code was typed or inputted incorrectly).  The following screenshot shows how the Plugin Command for the Foreground Parallax should look like.





    The Command Name is Show Foreground Parallax and the screenshot that you are seeing was/is an example of the inputted information for the parameters.  The default input for the parameters will be different, and if you want for no foreground parallax to be shown, then you can either leave the Foreground Parallax name as blank or set the opacity to 0.  Speaking of opacity, that's the one parameter that I wanted to see present on the plugin as RMXP did have opacity control for the fog.  Now, the following screenshot shows the Foreground Parallax in action.

    [url=https://forums.rpgmakerweb.com/attachments/foregroundparallaxsample-png.159426/]


    When I created the Foreground Parallax as an Event, I treated the Event as a "dummy" event and placed the Event on the top left corner.  I made sure that the Options (especially Walking) were deactivated as there was no need for the Options, and just to be on the safe side (even if there was no need to do that), I have set the Event as "Above characters".  However, the Trigger was set to Parallel in order for the Event to work.  Of course, the example was/is a basic way to use Foreground Parallax plugin.  I have attached the file of the Foreground Parallax plugin to this post, but even so, I'll be posting the code for the plugin in here as well, so that everyone will have a chance to look at how the code looks like.

    Spoiler: Foreground Parallax Plugin Code
                    JavaScript:        
    1. //=============================================================================
    2. // ForegroundParallax.js
    3. //=============================================================================
    4. /*:
    5. * @target MZ
    6. * @plugindesc Shows foreground parallax that can be used for fogs.
    7. * @author N/A (open-source, copyleft)
    8. *
    9. * @help ForegroundParallax.js
    10. *
    11. * This plugin provides a command for showing the foreground parallax.  The
    12. * opacity of the foreground parallax has to be higher than 0 in order for
    13. * the foreground parallax to be visible.  The foreground parallax becomes
    14. * more visible with a very high opacity.
    15. *
    16. * @command on
    17. * @text Show Foreground Parallax
    18. * @desc Shows the foreground parallax
    19. *
    20. * @arg parallaxName
    21. * @type string
    22. * @default
    23. * @text Foreground Parallax
    24. * @desc Filename of the parallax image
    25. *
    26. * @arg lockParallax
    27. * @type boolean
    28. * @on On
    29. * @off Off
    30. * @default false
    31. * @text Lock Parallax
    32. * @desc Keep the Foreground Parallax in locked position
    33. *
    34. * @arg loopHorizontally
    35. * @type boolean
    36. * @on On
    37. * @off Off
    38. * @default false
    39. * @text Loop Horizontally
    40. * @desc Turns Loop Horizontally on/off
    41. *
    42. * @arg loopVertically
    43. * @type boolean
    44. * @on On
    45. * @off Off
    46. * @default false
    47. * @text Loop Vertically
    48. * @desc Turns Loop Vertically on/off
    49. *
    50. * @arg scrollX
    51. * @type number
    52. * @min -32
    53. * @max 32
    54. * @default 0
    55. * @text Horizontal Scroll
    56. * @desc Horizontal scroll value (-32 - 32)
    57. *
    58. * @arg scrollY
    59. * @type number
    60. * @min -32
    61. * @max 32
    62. * @default 0
    63. * @text Vertical Scroll
    64. * @desc Vertical scroll value (-32 - 32)
    65. *
    66. * @arg parallaxOpacity
    67. * @type number
    68. * @min 0
    69. * @max 255
    70. * @default 64
    71. * @text Opacity
    72. * @desc Opacity of the parallax foreground (0 - 255)
    73. */
    74. (() => {
    75.       //-----------------------------------------------------------------------------
    76.     // PluginManager
    77.     //
    78.   
    79.       const pluginName = "ForegroundParallax";
    80.     PluginManager.registerCommand(pluginName, "on", args => {
    81.         name = String(args.parallaxName);
    82.         lock = eval(args.lockParallax);
    83.         loopX = eval(args.loopHorizontally);
    84.         loopY = eval(args.loopVertically);
    85.         sx = Number(args.scrollX);
    86.         sy = Number(args.scrollY);
    87.         opacity = Number(args.parallaxOpacity);
    88.         $gameMap.showFog(name, lock, loopX, loopY, sx, sy, opacity);
    89.     });
    90.   
    91.     //-----------------------------------------------------------------------------
    92.     // Game_Map
    93.     //
    94.     // The game object class for a map. It contains scrolling and passage
    95.     // determination functions.
    96.   
    97.     Game_Map.prototype.initialize = function() {
    98.         this._interpreter = new Game_Interpreter();
    99.         this._mapId = 0;
    100.         this._tilesetId = 0;
    101.         this._events = [];
    102.         this._commonEvents = [];
    103.         this._vehicles = [];
    104.         this._displayX = 0;
    105.         this._displayY = 0;
    106.         this._nameDisplay = true;
    107.         this._scrollDirection = 2;
    108.         this._scrollRest = 0;
    109.         this._scrollSpeed = 4;
    110.         this._parallaxName = '';
    111.         this._parallaxZero = false;
    112.         this._parallaxLoopX = false;
    113.         this._parallaxLoopY = false;
    114.         this._parallaxSx = 0;
    115.         this._parallaxSy = 0;
    116.         this._parallaxX = 0;
    117.         this._parallaxY = 0;
    118.         this._fogName = '';
    119.         this._fogZero = false;
    120.         this._fogLoopX = false;
    121.         this._fogLoopY = false;
    122.         this._fogSx = 0;
    123.         this._fogSy = 0;
    124.         this._fogX = 0;
    125.         this._fogY = 0;
    126.         this._fogOpacity = 0;
    127.         this._battleback1Name = null;
    128.         this._battleback2Name = null;
    129.         this.createVehicles();
    130.     };
    131.   
    132.     Game_Map.prototype.setup = function(mapId) {
    133.         if (!$dataMap) {
    134.             throw new Error('The map data is not available');
    135.         }
    136.         this._mapId = mapId;
    137.         this._tilesetId = $dataMap.tilesetId;
    138.         this._displayX = 0;
    139.         this._displayY = 0;
    140.         this.refereshVehicles();
    141.         this.setupEvents();
    142.         this.setupScroll();
    143.         this.setupParallax();
    144.         this.setupFog();
    145.         this.setupBattleback();
    146.         this._needsRefresh = false;
    147.     };
    148.   
    149.     Game_Map.prototype.fogName = function() {
    150.         return this._fogName;
    151.     };
    152.   
    153.     Game_Map.prototype.fogOpacity = function() {
    154.         return this._fogOpacity;
    155.     };
    156.   
    157.     Game_Map.prototype.setupFog = function() {
    158.         this._fogName = "";
    159.         this._fogZero = false;
    160.         this._fogLoopX = false;
    161.         this._fogLoopY = false;
    162.         this._fogSx = 0;
    163.         this._fogSy = 0;
    164.         this._fogX = 0;
    165.         this._fogY = 0;
    166.         this._fogOpacity = 0;
    167.     };
    168.   
    169.     Game_Map.prototype.setDisplayPos = function(x, y) {
    170.         if (this.isLoopHorizontal()) {
    171.             this._displayX = x.mod(this.width());
    172.             this._parallaxX = x;
    173.             this._fogX = x;
    174.         } else {
    175.             var endX = this.width() - this.screenTileX();
    176.             this._displayX = endX < 0 ? endX / 2 : x.clamp(0, endX);
    177.             this._parallaxX = this._displayX;
    178.             this._fogX = this._displayX;
    179.         }
    180.         if (this.isLoopVertical()) {
    181.             this._displayY = y.mod(this.height());
    182.             this._parallaxY = y;
    183.             this._fogY = y;
    184.         } else {
    185.             var endY = this.height() - this.screenTileY();
    186.             this._displayY = endY < 0 ? endY / 2 : y.clamp(0, endY);
    187.             this._parallaxY = this._displayY;
    188.             this._fogY = this._displayY;
    189.         }
    190.     };
    191.   
    192.     Game_Map.prototype.fogOx = function() {
    193.         if (this._fogZero) {
    194.             return this._fogX * this.tileWidth();
    195.         } else if (this._fogLoopX) {
    196.             return this._fogX * this.tileWidth() / 2;
    197.         } else {
    198.             return 0;
    199.         }
    200.     };
    201.   
    202.     Game_Map.prototype.fogOy = function() {
    203.         if (this._fogZero) {
    204.             return this._fogY * this.tileHeight();
    205.         } else if (this._fogLoopY) {
    206.             return this._fogY * this.tileHeight() / 2;
    207.         } else {
    208.             return 0;
    209.         }
    210.     };
    211.   
    212.     Game_Map.prototype.scrollDown = function(distance) {
    213.         if (this.isLoopVertical()) {
    214.             this._displayY += distance;
    215.             this._displayY %= $dataMap.height;
    216.             if (this._parallaxLoopY) {
    217.                 this._parallaxY += distance;
    218.             }
    219.             if (this._fogLoopY) {
    220.                 this._fogY += distance;
    221.             }
    222.         } else if (this.height() >= this.screenTileY()) {
    223.             var lastY = this._displayY;
    224.             this._displayY = Math.min(
    225.                 this._displayY + distance,
    226.                 this.height() - this.screenTileY()
    227.             );
    228.             this._parallaxY += this._displayY - lastY;
    229.             this._fogY += this._displayY - lastY;
    230.         }
    231.     };
    232.   
    233.     Game_Map.prototype.scrollLeft = function(distance) {
    234.         if (this.isLoopHorizontal()) {
    235.             this._displayX += $dataMap.width - distance;
    236.             this._displayX %= $dataMap.width;
    237.             if (this._parallaxLoopX) {
    238.                 this._parallaxX -= distance;
    239.             }
    240.             if (this._fogLoopX) {
    241.                 this._fogX -= distance;
    242.             }
    243.         } else if (this.width() >= this.screenTileX()) {
    244.             var lastX = this._displayX;
    245.             this._displayX = Math.max(this._displayX - distance, 0);
    246.             this._parallaxX += this._displayX - lastX;
    247.             this._fogX += this._displayX - lastX;
    248.         }
    249.     };
    250.   
    251.     Game_Map.prototype.scrollRight = function(distance) {
    252.         if (this.isLoopHorizontal()) {
    253.             this._displayX += distance;
    254.             this._displayX %= $dataMap.width;
    255.             if (this._parallaxLoopX) {
    256.                 this._parallaxX += distance;
    257.             }
    258.             if (this._fogLoopX) {
    259.                 this._fogX += distance;
    260.             }
    261.         } else if (this.width() >= this.screenTileX()) {
    262.             var lastX = this._displayX;
    263.             this._displayX = Math.min(
    264.                 this._displayX + distance,
    265.                 this.width() - this.screenTileX()
    266.             );
    267.             this._parallaxX += this._displayX - lastX;
    268.             this._fogX += this._displayX - lastX;
    269.         }
    270.     };
    271.   
    272.     Game_Map.prototype.scrollUp = function(distance) {
    273.         if (this.isLoopVertical()) {
    274.             this._displayY += $dataMap.height - distance;
    275.             this._displayY %= $dataMap.height;
    276.             if (this._parallaxLoopY) {
    277.                 this._parallaxY -= distance;
    278.             }
    279.             if (this._fogLoopY) {
    280.                 this._fogY -= distance;
    281.             }
    282.         } else if (this.height() >= this.screenTileY()) {
    283.             var lastY = this._displayY;
    284.             this._displayY = Math.max(this._displayY - distance, 0);
    285.             this._parallaxY += this._displayY - lastY;
    286.             this._fogY += this._displayY - lastY;
    287.         }
    288.     };
    289.   
    290.     var _Game_Map_update = Game_Map.prototype.update;
    291.     Game_Map.prototype.update = function(sceneActive) {
    292.         _Game_Map_update.call(this, sceneActive);
    293.         this.updateFog();
    294.     };
    295.   
    296.     Game_Map.prototype.updateFog = function() {
    297.         if (this._fogLoopX) {
    298.             this._fogX -= this._fogSx / this.tileWidth() / 2;
    299.         }
    300.         if (this._fogLoopY) {
    301.             this._fogY -= this._fogSy / this.tileHeight() / 2;
    302.         }
    303.     };
    304.   
    305.     Game_Map.prototype.showFog = function(name, lock, loopX, loopY, sx, sy, opacity) {
    306.         this._fogName = name;
    307.         this._fogZero = lock;
    308.         if (this._fogLoopX && !loopX) {
    309.             this._fogX = 0;
    310.         }
    311.         if (this._fogLoopY && !loopY) {
    312.             this._fogY = 0;
    313.         }
    314.         this._fogLoopX = loopX;
    315.         this._fogLoopY = loopY;
    316.         this._fogSx = sx;
    317.         this._fogSy = sy;
    318.         this._fogOpacity = opacity;
    319.     };
    320.   
    321.     //-----------------------------------------------------------------------------
    322.     // Spriteset_Map
    323.     //
    324.     // The set of sprites on the map screen.
    325.   
    326.     var _Spriteset_Map_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
    327.     Spriteset_Map.prototype.createLowerLayer = function() {
    328.         _Spriteset_Map_createLowerLayer.call(this);
    329.         this.createFog();
    330.     };
    331.   
    332.     var _Spriteset_Map_update = Spriteset_Map.prototype.update;
    333.     Spriteset_Map.prototype.update = function() {
    334.         _Spriteset_Map_update.call(this);
    335.         this.updateFog();
    336.     };
    337.   
    338.     Spriteset_Map.prototype.createFog = function() {
    339.         this._fog = new TilingSprite();
    340.         this._fog.move(0, 0, Graphics.width, Graphics.height);
    341.         this._baseSprite.addChild(this._fog);
    342.     };
    343.   
    344.     Spriteset_Map.prototype.updateFog = function() {
    345.         if (this._fogName !== $gameMap.fogName()) {
    346.             this._fogName = $gameMap.fogName();
    347.             this._fog.bitmap = ImageManager.loadParallax(this._fogName);
    348.         }
    349.         if (this._fog.bitmap) {
    350.             this._fog.origin.x = $gameMap.fogOx();
    351.             this._fog.origin.y = $gameMap.fogOy();
    352.             this._fog.opacity = $gameMap.fogOpacity();
    353.         }
    354.     };
    355. })();
    复制代码


    Once again, the plugin is open source and copyleft, so there's no need to give me credit for it and you can alter the plugin with full permission.

    UPDATE: The Lock Parallax option has been added to the plugin.  Also, some fixes and improvements were done on the plugin.


    本贴来自国际rpgmaker官方论坛作者:Lion Blade Soler处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/foreground-parallax-for-mz-updated-with-lock-parallax-option.126811/

    本帖子中包含更多资源

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

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-16 15:52 , Processed in 0.133620 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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