Class Text

Classdesc

Text class, used for rendering text

Example

 const text = new Text({
text: "Hello, World!",
coordinates: [0, 0],
font: "Arial",
fontSize: 20,
color: "black"
});

Hierarchy (view full)

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?

color: string

The color of the text, in hex or rgb format

convex: boolean

true if the object is convex, false otherwise

coordinates: Vec2

The coordinates of the text

ctx: null | CanvasRenderingContext2D
font: string

The font of the text, eg: "Arial", "Times New Roman", etc.

fontSize: number

The font size of the text, in pixels

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

text: string

The text to render

type: string

The type of the object, "text"

Methods

  • 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

  • Draws the text onto the provided drawing context. 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

  • Gets the height, as rendered, of the text

    Parameters

    • scene: null | Scene

      The scene that the text is in

    Returns number

    The height of the text, in pixels

  • Gets the width, as rendered, of the text

    Parameters

    • scene: null | Scene

      The scene that the text is in

    Returns number

    The width of the text, in pixels

  • 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

  • Gets a list of points representing the bounding box of the text

    Returns Vec2[]

    A list of points representing the bounding box of the text

  • 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

  • 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

Generated using TypeDoc