Rotate Triangle Around Center

Demonstrates how to rotate a Triangle geometry object around its own center point and render the results using Graphics.

Rotate Triangle Around Center, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    t = 0;
    triangle;
    graphics;

    create ()
    {
        this.graphics = this.add.graphics({ lineStyle: { width: 2, color: 0xaaaa00 } });

        this.triangle = new Phaser.Geom.Triangle.BuildRight(300, 360, 300, 300);
    }

    update ()
    {
        this.graphics.clear();

        this.t += 0.01;

        Phaser.Geom.Triangle.Rotate(this.triangle, Math.sin(this.t) * 0.04);

        this.graphics.strokeTriangleShape(this.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