Class GameObject

Classdesc

Base class for all objects in the scene

Example

 const gameObject = new GameObject({
physicsEnabled: true,
physicsOptions: {
restitution: 0.5
}
});

Example

 const gameObject = new GameObject();

Hierarchy (view full)

Indexable

[key: string]: any

Constructors

Properties

_state: {
    [key: string]: any;
}

used for state() and returnState(), builds states that are returnable. Stacking two states is destructive.

Type declaration

  • [key: string]: any
blockedBy: GameObject[]

List of objects that block this object

blocks: GameObject[]

List of objects that this object blocks

body: any

reference to the physics body (matter.js). Empty if physics is not enabled

bounds: number[]

how the object is bounded in the scene (set with scene.setBoundaries())

boundsActive: boolean

are the bounds active on this object?

convex: boolean

true if the object is convex, false otherwise

coordinates: Vec2

coordinates of the object, or the top left most point of the object

gameObjectOptions: GameObjectOptions

Game object options of the game object (for serialization and recreation)

hitbox: Vec2

Hitbox of the object, if the object is a square

id: string

unique ID for each object

isLocalPlayer: boolean

True if the object is the local player, false otherwise

meta: any

Meta data of the object

physicsEnabled: boolean

boolean if physics is enabled on the object

physicsOptions: PhysicsOptions

options for the physics engine

pinRef: "center" | "coordinates"

Reference point to pin the object to (only applies if the object is pinned)

pinned: null | GameObject

does nothing!

points: Vec2[]

points of the object (used for collision detection)

square: boolean

True if the object is a square, false otherwise

type: string

Type of the object, either "gameObject", "sprite", or "polygon"

Methods

  • Activates bounds on that object

    Returns void

  • Applies a force to the object (only works if physics enabled)

    Parameters

    • vector: Vec2

      The force vector to apply to the object

    Returns void

  • Checks for a collision with another object

    Parameters

    • object: GameObject

      The object to check for a collision with

    Returns boolean | Boolean

    Boolean, true of the object is colliding with the other object, false otherwise

  • Checks for a collision with a polygon

    Parameters

    • polygon: Vec2[]

      The polygon (lower case, not type Polygon) to check for a collision with

    Returns boolean | Boolean

    Boolean, true of the object is colliding with the other object, false otherwise

  • Disables bounds on that object

    Returns void

  • Draws the object on the provided drawing context, in accordance with the camera position. This is handled automatically with scene and scene managers

    Parameters

    Returns void

  • Draws the object's label on top of the object The label is the objects meta label (eg: object.meta.label = "...")

    Parameters

    Returns void

  • Top level move function (works with both physics enabled and disabled)... needs helper functions getWidth(), getHeight() to be defined. Recommended to re-write based on your use case (if extending)

    Parameters

    • vector: Vec2

      Vector to move the object by

    • continueAfterPhysics: boolean = true

      If set to false, the object will not move if physics are not enabled. If true, the object will move if physics are not enabled. True by defualt

    Returns Boolean

    Boolean, true if the move was successful, false if it was not (if it was out of bounds, it will not move)

  • Moves an object that has physics enabled by a vector (no forces pr boundaries involved)

    Parameters

    • vector: Vec2

      The vector to move the object by

    Returns true | Boolean

    Whether the object was moved or not (if it was out of bounds, it will not move)

  • Modifies pin to a game object

    Parameters

    • object: GameObject

      The game object to pin to

    • to: "center" | "coordinates"

      The reference point to pin to (either "center" or "coordinates")

    Returns void

  • Returns the gameobject represented as an array of points.

    Returns Vec2[]

    An array of points (eg: objects bounds). used for collision detection

  • Returns the gameobject represented as an array of points, with an offset applied.

    Parameters

    • offset: Vec2

      The offset to apply to the object

    Returns Vec2[]

    List of points that make up the object, with the offset applied

  • Returns to the old state (before state() was called). Used for clicking

    Returns void

  • Sets the object's bounds (where it can move)

    Parameters

    • bounds: number[]

      The bounds to set the object to

    Returns void

  • Changes an attribute of the object (non destructive). To return to the original object, use returnState. Used for clicking

    Parameters

    • attr: string

      The attribute to change

    • value: any

      The new value of that attribute

    Returns void

  • Removes the pinned object

    Returns void

  • Updates object physics 1 tick

    Returns void

Generated using TypeDoc