rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.18k stars 259 forks source link

Add game objects from outside rexUI dialog #436

Open dtturcotte opened 1 month ago

dtturcotte commented 1 month ago

For some reason, I can't pass in a game object, like an image, into rexUI dialog and have it display. The image seems to only show if I create the image directly within the config object of dialog. This is the case even when I add the image to the same scene, and set the depth to higher than its other elements. If I remove the background (a roundrectangle), however, the image shows. So, it seems to be simply blocked by other elements.

    create() {
        var dialog = this.rexUI.add.dialog({
            x: 400,
            y: 300,

            background: ...,

            title: ...,

            content: this.add.image(0, 0, 'https://i.imgur.com/123.png'), // This shows the image
    create() {
        const image = this.add.image(0, 0, 'https://i.imgur.com/123.png')

        var dialog = this.rexUI.add.dialog({
            x: 400,
            y: 300,

            background: ...,

            title: ...,

            content: image, // This doesn't show the image
rexrainbow commented 1 month ago

UI element of rexUI usually does not change depth (order of rendering) of children game objects. It seems that Background is created after Image, thus Background will render after Image. To solve this issue, you can set depth of Background manually, or

var background = dialog.getElement('background');
dialog.sendChildToBack(background);

Reference