Triangle Contains Point

Checks if the mouse pointer is inside a geometric triangle and changes the shape's color based on the result.

Triangle Contains Point, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        const graphics = this.add.graphics();

        const triangle = new Phaser.Geom.Triangle(400, 100, 100, 500, 700, 500);

        graphics.fillStyle(0x00ff00);
        graphics.fillTriangleShape(triangle);

        this.input.on('pointermove', pointer =>
        {

            graphics.clear();

            if (Phaser.Geom.Triangle.ContainsPoint(triangle, pointer))
            {
                graphics.fillStyle(0xff0000);
            }
            else
            {
                graphics.fillStyle(0x00ff00);
            }

            graphics.fillTriangleShape(triangle);

        });
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    width: 800,
    height: 600,
    type: Phaser.AUTO,
    parent: 'game-container',
    scene: Example
};

const game = new Phaser.Game(config);

More in Triangle32 examples