You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:PhaserRexUI插件UI元素不显示仅边界可见问题

问题:RexRainbow Phaser UI插件创建的元素不可见,但能看到drawBounds的红色边界

使用RexRainbow Phaser UI插件时,创建的所有UI元素均无法显示,但调用drawBounds()方法绘制边界时,能看到红色的边界框。

问题代码片段

//UI
var tabs = this.rexUI.add
  .tabs({
    x: 400,
    y: 1600,

    panel: this.rexUI.add.gridTable({
      background: this.rexUI.add.roundRectangle(
        0,
        0,
        20,
        10,
        10,
        0x4e342e
      ),

      table: {
        width: 250,
        height: 400,

        cellWidth: 120,
        cellHeight: 60,
        columns: 1,
        mask: {
          padding: 2,
        },
      },

      slider: {
        //scroll bar
        track: this.rexUI.add.roundRectangle(
          0,
          0,
          20,
          10,
          10,
          this.COLOR_DARK
        ),
        thumb: this.rexUI.add.roundRectangle(
          0,
          0,
          5,
          40,
          10,
          this.COLOR_LIGHT
        ),
      }
  })
  .layout()
  .drawBounds(this.add.graphics(), 0xff0000); //debug for ui

解决思路及方案

  • 检查元素位置是否超出画布:代码中tabs的y: 1600,如果你的游戏画布高度小于1600,整个UI组件会被放到屏幕可视区域外。尝试修改为合理的y值,比如y: 200。

  • 补全UI组件的必要配置:

    • tabs组件缺少tabs配置项,没有定义标签按钮,导致组件结构不完整;
    • gridTable缺少createCellCallback回调,无法生成可显示的单元格内容。
      示例修正:
    // 提前定义颜色变量
    this.COLOR_DARK = 0x2d2d2d;
    this.COLOR_LIGHT = 0xffffff;
    this.TAB_COLOR = 0x8d6e63;
    
    var tabs = this.rexUI.add
      .tabs({
        x: 400,
        y: 200,
        // 添加tabs配置
        tabs: this.rexUI.add.tabs({
          buttons: [
            this.rexUI.add.label({
              background: this.rexUI.add.roundRectangle(0,0,100,40,5,this.TAB_COLOR),
              text: this.add.text(0,0,"Tab1"),
              space: {left:10,right:10,top:5,bottom:5}
            }),
            this.rexUI.add.label({
              background: this.rexUI.add.roundRectangle(0,0,100,40,5,this.TAB_COLOR),
              text: this.add.text(0,0,"Tab2"),
              space: {left:10,right:10,top:5,bottom:5}
            })
          ],
          space: {left: 10, right:10, top:5, bottom:5, item:10},
          align: 'center'
        }),
        panel: this.rexUI.add.gridTable({
          background: this.rexUI.add.roundRectangle(0,0,20,10,10,0x4e342e),
          table: {
            width:250,
            height:400,
            cellWidth:120,
            cellHeight:60,
            columns:1,
            mask: {padding:2},
            // 添加单元格创建回调
            createCellCallback: function(cell, cellIndex, columnIndex, rowIndex) {
              return this.rexUI.add.label({
                background: this.rexUI.add.roundRectangle(0,0,110,50,5,0x6d4c41),
                text: this.add.text(0,0,"Item "+cellIndex),
                space: {left:10,right:10,top:5,bottom:5}
              });
            },
            // 模拟表格数据
            items: Array.from({length:10}, (_,i) => i)
          },
          slider: {
            track: this.rexUI.add.roundRectangle(0,0,20,10,10,this.COLOR_DARK),
            thumb: this.rexUI.add.roundRectangle(0,0,5,40,10,this.COLOR_LIGHT)
          },
          space: {left:10,right:10,top:10,bottom:10}
        }),
        space: {top:10}
      })
      .layout()
      .drawBounds(this.add.graphics(), 0xff0000);
    // 确保组件添加到场景
    this.add.existing(tabs);
    
  • 确认颜色变量已定义:代码中使用的this.COLOR_DARK和this.COLOR_LIGHT需要在场景中提前赋值,否则滑块元素会因颜色无效而不显示。

  • 确保组件加入场景显示列表:调用this.add.existing(tabs)确保UI组件被正确添加到场景的显示层级中,避免因层级问题导致不可见。

内容的提问来源于stack exchange,提问作者Vatsa Pandey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 11:25:43