@pietal.dev/engine
    Preparing search index...

    Class PolygonBody

    Hierarchy

    • Polygon
      • PolygonBody

    Implements

    Index

    Constructors

    Properties

    _group: number

    group for collision filtering

    angle: number
    bbox: BBox

    bounding box cache, without padding

    calcPoints: Vector[]
    centered: boolean

    is body centered

    convexPolygons: Polygon[]

    optimization for convex polygons

    destroy$: Subject<void> = ...

    When Lifecycle Object is destroyed, it emits and closes this subject. Along with destroying his children, which in turn behave the same.

    dirty: boolean

    was the polygon modified and needs update in the next checkCollision

    edges: Vector[]
    gameObject: LifecycleParent

    Parent GameObject is assigned at creation.

    isConvex: boolean

    is it a convex polgyon as opposed to a hollow inside (concave) polygon

    isStatic: boolean

    static bodies don't move but they collide

    isTrigger: boolean

    trigger bodies move but are like ghosts

    label: string = 'PolygonBody'

    Each Lifecycle Object has label for pixi debugging.

    maxX: number

    maximum x bound of body

    maxY: number

    maximum y bound of body

    minX: number

    minimum x bound of body

    minY: number

    minimum y bound of body

    normals: Vector[]
    offset: Vector
    padding: number

    bodies are not reinserted during update if their bbox didnt move outside bbox + padding

    points: Vector[]
    pointsBackup: Vector[]

    backup of points used for scaling

    pos: Vector
    scaleVector: Vector

    scale Vector of body

    system?: System

    reference to collision system

    type: Ellipse | Polygon | Box | Line | Point

    type of body

    typeGroup: Ellipse | Polygon | Box | Line | Point

    faster than type

    update$: Subject<number> = ...

    When Lifecycle Object is updated, it emits this subject. Along with updating his children, which in turn behave the same.

    userData?: any

    allows the user to set any misc data for client use

    Accessors

    • get group(): number

      group for collision filtering

      Based on Box2D (tutorial)

      Values in BodyGroup are predefined and used each the body type and should not be used for custom filtering

      0b00000001 << 16 to 0b01000000 << 16 (max 0x7fffffff) are free to use for custom groups

      Returns number

      canInteract for how groups are used

      0x7fffffff // member of all groups (can interact with everyting)
      
    • set group(group: number): void

      group for collision filtering

      Based on Box2D (tutorial)

      Values in BodyGroup are predefined and used each the body type and should not be used for custom filtering

      0b00000001 << 16 to 0b01000000 << 16 (max 0x7fffffff) are free to use for custom groups

      Parameters

      • group: number

      Returns void

      canInteract for how groups are used

      0x7fffffff // member of all groups (can interact with everyting)
      
    • get isCentered(): boolean

      is polygon centered?

      Returns boolean

    • set isCentered(center: boolean): void

      flag to set is polygon centered

      Parameters

      • center: boolean

      Returns void

    • get scale(): number

      allow approx getting of scale

      Returns number

    • set scale(scale: number): void

      allow easier setting of scale

      Parameters

      • scale: number

      Returns void

    • get scaleX(): number

      allow exact getting of scale x - use setScale(x, y) to set

      Returns number

    • get scaleY(): number

      allow exact getting of scale y - use setScale(x, y) to set

      Returns number

    • get x(): number

      Returns number

    • set x(x: number): void

      updating this.pos.x by this.x = x updates AABB

      Parameters

      • x: number

      Returns void

    • get y(): number

      Returns number

    • set y(y: number): void

      updating this.pos.y by this.y = y updates AABB

      Parameters

      • y: number

      Returns void

    Methods

    • Draws exact collider on canvas context

      Parameters

      • context: CanvasRenderingContext2D

      Returns void

    • Draws Bounding Box on canvas context

      Parameters

      • context: CanvasRenderingContext2D

      Returns void

    • Returns Polygon

    • get body bounding box, without padding

      Returns BBox

    • Returns Vector

    • returns body split into convex polygons, or empty array for convex bodies

      Returns Polygon[]

    • Get edge line by index

      Parameters

      • index: number

      Returns { end: { x: number; y: number }; start: { x: number; y: number } }

    • if true, polygon is not an invalid, self-crossing polygon

      Returns boolean

    • update instantly or mark as dirty

      Parameters

      • OptionalupdateNow: boolean

      Returns void

    • update position BY MOVING FORWARD IN ANGLE DIRECTION

      Parameters

      • Optionalspeed: number
      • OptionalupdateNow: boolean

      Returns Polygon

    • rotates polygon points by angle, in radians

      Parameters

      • angle: number

      Returns Polygon

    • used to do stuff with temporarily disabled rotation

      Parameters

      • callback: () => void

      Returns void

    • Parameters

      • angle: number
      • OptionalupdateNow: boolean

      Returns Polygon

    • Parameters

      • offset: Vector
      • OptionalupdateNow: boolean

      Returns Polygon

    • sets polygon points to new array of vectors

      Parameters

      • points: Vector[]

      Returns Polygon

    • update position BY TELEPORTING

      Parameters

      • x: number
      • y: number
      • OptionalupdateNow: boolean

      Returns Polygon

    • update scale

      Parameters

      • x: number
      • Optionaly: number
      • OptionalupdateNow: boolean

      Returns Polygon

    • translates polygon points in x, y direction

      Parameters

      • x: number
      • y: number

      Returns Polygon

    • inner function for after position change update aabb in system and convex inner polygons

      Parameters

      • OptionalupdateNow: boolean

      Returns void

    • update the position of the decomposed convex polygons (if any), called after the position of the body has changed

      Returns void

    • updates convex polygons cache in body

      Parameters

      • Optionalconvex: Polygon[]

      Returns void

    • after points update set is convex

      Returns void