查看: 90|回复: 0

[转载发布] [插件]菜单UI的自适应图片精灵,该如何解决内容覆盖问题?

[复制链接]
  • TA的每日心情
    开心
    2024-5-10 09:55
  • 签到天数: 37 天

    连续签到: 3 天

    [LV.5]常住居民I

    2028

    主题

    32

    回帖

    7260

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5184
    OK点
    16
    积分
    7260
    发表于 同元九百九十六年三月十七日(春) | 显示全部楼层 |阅读模式
    我试图实现一个插件,其作用是新建一个窗口,并为这个窗口创建选项和自适应图片,即为其设置背景时,能够自动将背景和窗口的大小适应。
    为此,我向这个窗口添加了一个图片精灵,其能自动缩放以适应窗口的尺寸,但是,当我实际运行时,她却覆盖了原本窗口的所有内容。

    ↓比如,我只能看到一张自适应好了的图片,却不能看到任何选项。

    为此,我查询了很多资料,解决方法似乎是将图片精灵在内容之前加载出来,但是我不知道该如何实现……
    求求大佬帮助QAQ
    ↓这个是代码
    RUBY 代码
    1. //这个窗口构造,设置了“属性”、“武器”、“装备”、"能力"一共四个选项
    2. //继承窗口
    3. function Window_OriginBase() {
    4.     this.initialize(...arguments);
    5. }
    6. Window_OriginBase.prototype = Object.create(Window_Command.prototype);
    7. Window_OriginBase.prototype.constructor = Window_OriginBase;
    8. //设置透明度和边框大小
    9. Window_OriginBase.prototype.initialize = function(rect) {
    10.     Window_Command.prototype.initialize.call(this,rect);
    11.     this.opacity = 0;
    12.     this.padding = 0;
    13. }
    14. //设置选项最大列数
    15. Window_OriginBase.prototype.maxCols = function() {
    16.     return 4;
    17. };
    18. //设置选项
    19. Window_OriginBase.prototype.makeCommandList = function() {
    20.     if (this.needsCommand("attr")) {
    21.         this.addCommand("属性", "attr");
    22.     }
    23.     if (this.needsCommand("weapon")) {
    24.         this.addCommand("武器", "weapon");
    25.     }
    26.     if (this.needsCommand("equip")) {
    27.         this.addCommand("装备", "equip");
    28.     }
    29.     if (this.needsCommand("ability")) {
    30.         this.addCommand("能力", "ability");
    31.     }
    32. };
    33. //参考游戏原来的库摘抄的,作用好像是判断在原本游戏里有没有这个选项?
    34. Window_OriginBase.prototype.needsCommand = function(name) {
    35.     const table = ["attr", "weapon", "equip", "ability"];
    36.     const index = table.indexOf(name);
    37.     if (index >= 0) {
    38.         return $dataSystem.itemCategories[index];
    39.     }
    40.     return true;
    41. };
    42. //对应的场景
    43. function Scene_Origin() {
    44.     this.initialize(...arguments);
    45. }
    46. //基本
    47. Scene_Origin.prototype = Object.create(Scene_MenuBase.prototype);
    48. Scene_Origin.prototype.constructor = Scene_Origin;
    49. Scene_Origin.prototype.initialize = function() {
    50.     Scene_MenuBase.prototype.initialize.call(this);
    51.     ImageManager.loadBitmap("img/pictures/","SaveBg04");
    52. };
    53. //创建场景
    54. Scene_Origin.prototype.create = function() {
    55.     Scene_MenuBase.prototype.create.call(this);
    56.     this.createCommandWindow();
    57. };
    58. Scene_Origin.prototype.createCommandWindow = function() {
    59.     const rect = this.commandWindowRect();
    60.     this.win = new Window_OriginBase(rect);
    61.     //通过this.drawBg(rect)给窗口添加一个精灵,能够显示图片。
    62.     this.drawBg(rect);
    63.     //返回按钮
    64.     this.win.setHandler("cancel", this.popScene.bind(this));
    65.     //添加
    66.     this.addWindow(this.win);
    67. };
    68. //尺寸
    69. Scene_Origin.prototype.commandWindowRect = function() {
    70.     const ww = Graphics.width*0.45;
    71.     const wh = Graphics.height*0.1;
    72.     const wx = Graphics.width*0.5;
    73.     const wy = Graphics.height*0.8;
    74.     return new Rectangle(wx, wy, ww, wh);
    75. };
    76. //设置图片的函数
    77. Scene_Origin.prototype.drawBg = function(rect) {
    78.     //新建精灵
    79.     const sprite_origin = new Sprite();
    80.     sprite_origin.bitmap = ImageManager.loadBitmap("img/pictures/","SaveBg04");
    81.     //通过回调确保图片顺利加载
    82.     sprite_origin.bitmap.addLoadListener(function(){
    83.         //自适应宽高
    84.         sprite_origin.scale.x = rect.width/sprite_origin.bitmap.width;
    85.         sprite_origin.scale.y = rect.height/sprite_origin.bitmap.height;
    86.     }.bind(this));
    87.     //添加
    88.     this.win.addChild(sprite_origin);
    89. };
    复制代码

                 本帖来自P1论坛作者sumcat,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=487878  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-5-20 17:13 , Processed in 0.046969 second(s), 42 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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