Class Particle

Classdesc

Particle class, renders a single particle

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
angle: number

The angle of the particles (in radians)

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 sprite, or the top left most point of the sprite

gameObjectOptions: GameObjectOptions

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

height: number

height of the sprite

hitbox: Vec2

Hitbox of the object, if the object is a square

id: string

unique ID for each object

image: string

url of the image to use for the sprite

isLocalPlayer: boolean

True if the object is the local player, false otherwise

life: number

The life of the particles (in milliseconds)

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)

source: HTMLImageElement

the image element to use for the sprite

spawnedAt: number

The time the particle was spawned

speed: number

The speed of the particles (in pixels per tick)

spriteLoaded: boolean

true if the sprite is loaded, false otherwise

square: boolean

True if the object is a square, false otherwise

type: string

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

width: number

width of the sprite

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

  • Changes the sprites image source

    Parameters

    • image: string

      The new image URL to use for the sprite

    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 sprite 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

  • 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

  • Calculates the vertices of the sprite, with an offset applied

    Parameters

    • offset: Vec2

      The offset to apply to the sprite

    Returns Vec2[]

    The vertices of the sprite, with the offset applied

  • Loads the sprite, or reloads the image source when the image is changed

    Returns void

  • Reshapes the sprite according to the provided dimensions

    Parameters

    • width: number

      The new width of the sprite

    • height: number

      The new height of the sprite

    Returns void

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

    Returns void

  • Scales the sprite by the provided factor. 1 is the default size, 2 is twice the size, 0.5 is half the size, etc.

    Parameters

    • factor: number

      The factor to scale the sprite by

    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

Generated using TypeDoc