Hello! I was working with phaser in my own project when I got stuck in this very weird issue that took me a long time to investigate. I have 2 game objects, a rectangular menu, and some text on top of it, and I have pointerup events for both of them. When I click on the text, it does not receive the event, but instead the rectangle receives it, even though the text is rendered later and also on top of the rectangle. It took me a long time to figure out but it turns out that because I called set interactive first on the rectangle, if they both listen to the same event, only the first one that had setInteractive called receives it. Should it not be the first gameObject at the top in terms of depth?
As I have a library that abstracts away the rendering and the setInteractive call of the text and rectangle, I can’t really just “change” the order of setInteractive called on the game objects, and it doesn’t make sense to me intuitively, maybe I am missing something? Hopefully someone can help me with this
Sample code (the base phaser logic is abstracted away by vue, <Rectangle>
just calls scene.add.rectangle and setInteractive etc)
const rectangle1 = ref<GameObjects.Rectangle>();
const text1 = ref<GameObjects.Text>();
watch([rectangle1, text1 ], ([newRectangle1, text1 ]) => {
if (!(newRectangle1 && text1)) return;
newRectangle1.setInteractive(); <--- Swapping these 2 calls around would swap the console log messages
text1.setInteractive();
});
</script>
<template>
<Rectangle
:on-complete="
(rectangle) => {
rectangle1 = rectangle;
}
"
@[`${Input.Events.GAMEOBJECT_POINTER_UP}`]="
() => {
console.log('1');
}
"
/>
<Text
:on-complete="
(text) => {
text1 = text;
}
"
@[`${Input.Events.GAMEOBJECT_POINTER_UP}`]="
() => {
console.log('2');
}
"
/>