Circle Contains Rectangle

Demonstrates how to check if a Rectangle is fully contained within the bounds of a Circle using Phaser.Geom.Circle.ContainsRect.

Circle Contains Rectangle, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    a = 0;
    graphics;
    rect;
    circle;

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

        this.circle = new Phaser.Geom.Circle(400, 300, 250);
        this.rect = new Phaser.Geom.Rectangle(0, 0, 100, 100);
    }

    update ()
    {
        this.a += 0.01;

        if (this.a > Math.PI * 2)
        {
            this.a -= Math.PI * 2;
        }

        this.rect.x = 350 - Math.sin(this.a * 2) * 350;
        this.rect.y = 250 - Math.cos(this.a) * 250;

        this.graphics.clear();
        this.graphics.strokeCircleShape(this.circle);

        if (Phaser.Geom.Circle.ContainsRect(this.circle, this.rect))
        {
            this.graphics.fillStyle(0xff0000);
        }
        else
        {
            this.graphics.fillStyle(0x0000ff);
        }

        this.graphics.fillRectShape(this.rect);
    }
}

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 Circle22 examples