Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phaser.GameObjects.Container inside another Container call addedToScene when the scene is removed only #6078

Closed
BenoitFreslon opened this issue Apr 16, 2022 · 3 comments

Comments

@BenoitFreslon
Copy link

Version

In Phaser 3 example

Browser

  • Browser: Chrome, Safari

Description

Hello

Test this code, tap T to remove the scene and see that the container2.addedToScene event is called when the scene is removed.

Example Test Code

class ContainerTest extends Phaser.GameObjects.Container {
    constructor(scene, x, y) {
		super(scene, 166, 275);
        console.log("container:constructor");
	}

	addedToScene() {
		super.addedToScene()
		console.log("container:addedToScene");
	}
}

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#010101',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{

}

function create ()
{
    console.log("create");

    container = this.add.container(400, 300);

    container2 = new ContainerTest(this, 100, 100);
    container.add(container2);

    this.input.keyboard.on("keyup-T", () => {
        console.log("Input detected")
        this.scene.remove();
    })
}

@photonstorm
Copy link
Collaborator

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/gameobject-container-in-container-doesnt-call-addedtoscene-event/11530/2

@BenoitFreslon
Copy link
Author

BenoitFreslon commented Apr 19, 2022

I also tested to include a Container inside a Layer.
This time the addedToScene is called but the preUpdate is never called

class ContainerTest extends Phaser.GameObjects.Container {
    constructor(scene, x, y) {
		super(scene, 166, 275);
        console.log("ContainerTest:constructor");
	}

	addedToScene() {
		super.addedToScene()
		console.log("ContainerTest:addedToScene");
	}
    preUpdate(t,dt) {

        console.log("ContainerTest:preUpdate");
    }
}

class SpriteTest extends Phaser.GameObjects.Sprite {
    constructor(scene, x, y) {
		super(scene, 166, 275);
        console.log("SpriteTest:constructor");
	}

	addedToScene() {
		super.addedToScene()
		console.log("SpriteTest:addedToScene");
	}
    preUpdate(t,dt) {
        console.log("SpriteTest:preUpdate");
    }
}



var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#010101',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{

}

function create ()
{
    console.log("create");

    layer = this.add.layer();
    container = this.add.container(100,100);

    containerTest = new ContainerTest(this, 100, 100);
    layer.add(containerTest);
    //container.add(containerTest);

    //spriteTest = new SpriteTest(this, 100, 100);
    //layer.add(spriteTest);
    //container.add(spriteTest);


    this.input.keyboard.on("keyup-T", () => {
        console.log("Input detected")
        this.scene.remove();
    })
}

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants