LogoPixi’VN
pixi-jsInterfaces

Interface: ShapePrimitive

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:36

A basic interface that defines common properties and methods for all Pixi shape primitives. Provides a standard API for shape manipulation, hit testing, and bounds calculation.

Example

// Implement basic shape
class CustomShape implements ShapePrimitive {
    public readonly type = 'custom';
    public x = 0;
    public y = 0;

    // Implement required methods
    public contains(x: number, y: number): boolean {
        // Custom hit testing logic
        return true;
    }

    public getBounds(out?: Rectangle): Rectangle {
        // Custom bounds calculation
        return out || new Rectangle();
    }

    // ... implement other required methods
}
// Use in a container
container.hitArea = new CustomShape();

See

  • Rectangle For rectangular shape implementation
  • Circle For circular shape implementation
  • Polygon For polygon shape implementation

Advanced

Properties

type

> readonly type: string & object | SHAPE_PRIMITIVE

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:38

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


x

> readonly x: number

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:52

The X coordinate of the shape


y

> readonly y: number

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:54

The Y coordinate of the shape

Methods

clone()

> clone(): ShapePrimitive

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:44

Creates a clone of this ShapePrimitive instance.

Returns

ShapePrimitive


contains()

> contains(x, y): boolean

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:40

Checks whether the x and y coordinates passed to this function are contained within this ShapePrimitive.

Parameters

x

number

y

number

Returns

boolean


copyFrom()

> copyFrom(source): void

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:46

Copies the properties from another ShapePrimitive to this ShapePrimitive.

Parameters

source

ShapePrimitive

Returns

void


copyTo()

> copyTo(destination): void

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:48

Copies the properties from this ShapePrimitive to another ShapePrimitive.

Parameters

destination

ShapePrimitive

Returns

void


getBounds()

> getBounds(out?): Rectangle

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:50

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

Parameters

out?

Rectangle

Returns

Rectangle


strokeContains()

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

Defined in: node_modules/pixi.js/lib/maths/shapes/ShapePrimitive.d.ts:42

Checks whether the x and y coordinates passed to this function are contained within the stroke of this shape

Parameters

x

number

y

number

strokeWidth

number

alignment?

number

Returns

boolean