LogoPixi’VN
pixi-jsClasses

Class: Circle

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:29

The Circle object represents a circle shape in a two-dimensional coordinate system. Used for drawing graphics and specifying hit areas for containers.

Example

// Basic circle creation
const circle = new Circle(100, 100, 50);

// Use as hit area
container.hitArea = new Circle(0, 0, 100);

// Check point containment
const isInside = circle.contains(mouseX, mouseY);

// Get bounding box
const bounds = circle.getBounds();

Remarks

  • Defined by center (x,y) and radius
  • Supports point containment tests
  • Can check stroke intersections

See

Rectangle For rectangular shapes

Standard

Implements

Constructors

Constructor

> new Circle(x?, y?, radius?): Circle

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:100

Parameters

x?

number

The X coordinate of the center of this circle

y?

number

The Y coordinate of the center of this circle

radius?

number

The radius of the circle

Returns

Circle

Properties

radius

> radius: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:71

The radius of the circle

Example

// Basic radius setting
const circle = new Circle(100, 100);
circle.radius = 50;

// Calculate area
const area = Math.PI * circle.radius * circle.radius;

Default

0

type

> readonly type: SHAPE_PRIMITIVE

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:94

The type of the object, mainly used to avoid instanceof checks.

Example

// Check shape type
const shape = new Circle(0, 0, 50);
console.log(shape.type); // 'circle'

// Use in type guards
if (shape.type === 'circle') {
    console.log(shape.radius);
}

Remarks

  • Used for shape type checking
  • More efficient than instanceof
  • Read-only property

Default

'circle'

See

Implementation of

ShapePrimitive.type


x

> x: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:43

The X coordinate of the center of this circle

Example

// Basic x position
const circle = new Circle();
circle.x = 100;

// Center circle on point
circle.x = point.x;

Default

0

Implementation of

ShapePrimitive.x


y

> y: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:57

The Y coordinate of the center of this circle

Example

// Basic y position
const circle = new Circle();
circle.y = 200;

// Center circle on point
circle.y = point.y;

Default

0

Implementation of

ShapePrimitive.y

Methods

clone()

> clone(): Circle

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:121

Creates a clone of this Circle instance.

Returns

Circle

A copy of the Circle

Example

// Basic circle cloning
const original = new Circle(100, 100, 50);
const copy = original.clone();

// Clone and modify
const modified = original.clone();
modified.radius = 75;

// Verify independence
console.log(original.radius); // 50
console.log(modified.radius); // 75

See

Implementation of

ShapePrimitive.clone


contains()

> contains(x, y): boolean

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:147

Checks whether the x and y coordinates given are contained within this circle.

Uses the distance formula to determine if a point is inside the circle's radius.

Commonly used for hit testing in PixiJS events and graphics.

Parameters

x

number

The X coordinate of the point to test

y

number

The Y coordinate of the point to test

Returns

boolean

Whether the x/y coordinates are within this Circle

Example

// Basic containment check
const circle = new Circle(100, 100, 50);
const isInside = circle.contains(120, 120);

// Check mouse position
const circle = new Circle(0, 0, 100);
container.hitArea = circle;
container.on('pointermove', (e) => {
    // only called if pointer is within circle
});

See

Implementation of

ShapePrimitive.contains


copyFrom()

> copyFrom(circle): this

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:203

Copies another circle to this one.

Parameters

circle

Circle

The circle to copy from

Returns

this

Returns itself

Example

// Basic copying
const source = new Circle(100, 100, 50);
const target = new Circle();
target.copyFrom(source);

See

Implementation of

ShapePrimitive.copyFrom


copyTo()

> copyTo(circle): Circle

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:218

Copies this circle to another one.

Parameters

circle

Circle

The circle to copy to

Returns

Circle

Returns given parameter

Example

// Basic copying
const source = new Circle(100, 100, 50);
const target = new Circle();
source.copyTo(target);

See

Implementation of

ShapePrimitive.copyTo


getBounds()

> getBounds(out?): Rectangle

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:188

Returns the framing rectangle of the circle as a Rectangle object.

Parameters

out?

Rectangle

Optional Rectangle object to store the result

Returns

Rectangle

The framing rectangle

Example

// Basic bounds calculation
const circle = new Circle(100, 100, 50);
const bounds = circle.getBounds();
// bounds: x=50, y=50, width=100, height=100

// Reuse existing rectangle
const rect = new Rectangle();
circle.getBounds(rect);

See

Implementation of

ShapePrimitive.getBounds


strokeContains()

> strokeContains(x, y, width, alignment?): boolean

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:169

Checks whether the x and y coordinates given are contained within this circle including the stroke.

Parameters

x

number

The X coordinate of the point to test

y

number

The Y coordinate of the point to test

width

number

The width of the line to check

alignment?

number

The alignment of the stroke, 0.5 by default

Returns

boolean

Whether the x/y coordinates are within this Circle's stroke

Example

// Basic stroke check
const circle = new Circle(100, 100, 50);
const isOnStroke = circle.strokeContains(150, 100, 4); // 4px line width

// Check with different alignments
const innerStroke = circle.strokeContains(150, 100, 4, 1);   // Inside
const centerStroke = circle.strokeContains(150, 100, 4, 0.5); // Centered
const outerStroke = circle.strokeContains(150, 100, 4, 0);   // Outside

See

Implementation of

ShapePrimitive.strokeContains


toString()

> toString(): string

Defined in: node_modules/pixi.js/lib/maths/shapes/Circle.d.ts:219

Returns a string representation of an object.

Returns

string