I can’t figure out how to get a TilemapLayer to be the top input source for a mouse click. It seems like with all the GameObjects whatever you make the draw order that is what the input order is too but with the TilemapLayer for some reason even if it is draw on top its input order is not. Below is my test code to show this. I have a some text that is rendered underneath the TilemapLayer but when I click on the area where the Text is under the TilemapLayer the input handler for the text is processed first. I have done the same with other GameOjects and they behave as expected, it just seems to be the TilemapLayer. Any thoughts?
import * as Phaser from "phaser";
import images from '../assets/images/*.png'
export class Menu extends Phaser.Scene {
constructor() {super({key: 'examples' })}
preload() {
this.load.spritesheet('tilesheet', images.tiles, { frameWidth: 32, frameHeight: 32 })
}
create() {
let menuItem = this.add.text(10, 5, 'item', {backgroundColor:'red'}).setInteractive()
menuItem.on('pointerdown', this.pointerDownText, this)
this.input.enableDebug(menuItem)
let tilemap = {data: [[926,926,926,926,926,]]}
let map = this.make.tilemap(tilemap);
let tiles = map.addTilesetImage('tiles', 'tilesheet');
let board = map.createLayer('layer', 'tiles')!.setInteractive()
board.setPosition(0,0)
board.on('pointerdown', this.pointerDownMap, this)
this.input.enableDebug(board)
//board.setDepth(-10)
this.input.setTopOnly(false)
}
public pointerDownMap(pointer:Phaser.Input.Pointer, x:number, y:number, e:Phaser.Types.Input.EventData) {
console.log('Map - pointerDown')
}
public pointerDownText(pointer:Phaser.Input.Pointer, x:number, y:number, e:Phaser.Types.Input.EventData) {
console.log('Text - pointerDown')
}
}
const config: Phaser.Types.Core.GameConfig = {
type: Phaser.CANVAS,
width: 800,
height: 600,
scene: [Menu]
};
let game = new Phaser.Game(config);