graphics setInteractive not work correctly.
suppose: console outputs: 'btn pointerup'
result: nothing happened
preload() {
console.log('now loading...');
}
create() {
var btn = this.add.graphics();
btn.fillStyle(0xffff00, 1);
btn.fillRoundedRect(32, 32, 300, 200, 32);
// btn.setInteractive(new Phaser.Geom.Rectangle(0, 0, 300, 200));
btn.setInteractive();
btn.on('pointerup', function() {
console.log('btn pointerup');
}, this);
}
If rectangle param provided, will get phaser-3.15.1.min.js:1 Uncaught TypeError: n.hitAreaCallback is not a function error when pointer hover.
Graphics object does not have bounds, pass a geom shape
btn.setInteractive(new Phaser.Geom.Rectangle(0, 0, 300, 200), Phaser.Geom.Rectangle.Contains);
to define that bounds.
Or use rectangle shape game object (scene.add.rectangle(x, y, width, height, fillColor).setInteractive())
@rexrainbow Both suggestions works, thank you.
Most helpful comment
Graphics object does not have bounds, pass a geom shape
to define that bounds.
Or use rectangle shape game object (
scene.add.rectangle(x, y, width, height, fillColor).setInteractive())