Touch event on graphics

Hi everybody :slight_smile:

I want to do this :

var graphics = this.add.graphics();
        graphics.fillGradientStyle(0xffff00, 0xffff00, 0xff0000, 0xff0000, 1);
        graphics.fillRect(0, 700, game.config.width, 400);
        graphics.setInteractive().on('pointerdown', function(pointer, localX, localY, event){
            alert('e');
        });

But even if i touch with the cursor my rectangle, prrrrrrrt, he doesn’t care…

what i miss please ?

thx guys !

Graphics has no size, so no implicit hit area. You must pass a hit area and test function. See examples in Phaser.GameObjects.GameObject#setInteractive.

1 Like

thx for the reply :slight_smile:
ok, i’ll see how to do that !