I am trying to move images inside a container with drag and drop. I tryed all, but there is no way to focus sprite when I add input event (it always takes the container if I set setInteractive() to container, and takes nothing if I only set setInteractive() to images/sprites, tested with both childreens).
No matters if I try to catch the event in main scene making this.input.on(‘pointerdown’, (pointer, objects) => {here}) (I added this.input.topOnly = false, absoluty)
or inside container class making .on(‘pointerdown’, ()=>{here}) after setInteractive()
I think the problem is really easy: drag and drop a sprite inside container or from one container to another, but I cant event handle a simple pointerdown input in gameObject if its inside container
No :(. I tested this on container: this.disableInteractive() and this.removeInteractive().
No matters what I do, if I click on child into container there is not pointer event response :-/. I have been working with Phaser for a months without problems, this is the first time I am stucked
I know this should be really easy but I am sure this is not working. The only difference is I am typing the container in an external class, and then, in main scene, I make something like: this.inventory = new Inventory(this)
If you see the code on top, I am doing this in the container class:
var image = this.scene.add.sprite(0, 0, 1).setSize(27, 27).setInteractive()
this.add(image)
this.scene.input.setDraggable(image)
and then this in Main scene:
this.input.on("dragstart", function (pointer, gameObject) {
gameObject.setTint(0xff0000);
});
this.input.on("drag", function (pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on("dragend", function (pointer, gameObject) {
gameObject.clearTint();
});
The problem is that my game is a TileMap based game, and camera follows my player. Even when container have .setScrollFactor(0), the image appears correctly but the interactive area is not there, you have to use .setScrollFactor(0) to sprite AFTER .setInteractive()
I think this should be fixed in phaser core, if you set interactive a object that has scrollFactor 0 and is into container with scrollFactor 0, the interactive area should be scroll factor 0 too.