Class Entity

The Entity class represents a game object in the scene.

Hierarchy (view full)

Constructors

Properties

active: boolean = true

Whether the object is active and should be updated

angle: number = 0

Rotation angle (in radians)

angleDamping: number = 1

Rotation slowdown (0-1)

angleVelocity: number = 0

The object's angular velocity

animation?: Animation

The animation of the object sprite.

bounded: boolean = false

Whether the object is bounded by the scene and cannot move outside.

collideObjects: boolean = true

Whether the object collides with other objects

collideTiles: boolean = true

Whether the object is static and should not move

color?: Color

The color of the object (if no sprite).

damping: number = 1

The object's damping (0-1)

dead: boolean = false

Whether the object is dead and should be removed

elasticity: number = 0

The object's elasticity (0-1)

family?: string

The family of the object.

flipH: boolean = false

Whether the object is flipped horizontally (mirrored)

flipV: boolean = false

Whether the object is flipped vertically

force: Vector = ...

The force applied to the object (acceleration)

friction: number = 0.8

The object's friction (0-1)

gid?: number

The global ID of the object image from TMX map (if any).

gravityScale: number = 1

How much gravity affects the object

id: number = ...

The ID of the object.

image?: string

The image of the object (if any).

lastPos: Vector = ...

Last position of the object

layerId?: number

The layer ID of the object (if any).

mass: number = 1

The object's mass (0 is static)

maxSpeed: number = 1

Maximum speed

name?: string

The name of the object.

obj?: Record<string, any>
onGround: boolean | Entity = false

The object the entity is standing on

pos: Vector = ...

Current position of the object

properties: Record<string, any> = {}

Custom properties of the object

renderOrder: number = 0

Render order

scene: Scene
shape: Shape = Shape.Rectangle

The shape of the entity.

size: Vector = ...

The size of the object (scaled by tileSize)

solid: boolean = true

Whether the object is solid and collides with other objects

spawnTime: number = 0

Time the entity was spawned

sprite: Sprite = ...

The sprite of the object.

Sprite

ttl?: number

The time to live of the object in milliseconds.

type?: string

The type of the object.

visible: boolean = true

Whether the object is visible and should be drawn

Methods

  • Checks if this entity collides with another entity.

    Parameters

    • entity: Entity

      The entity to check collision with.

    Returns boolean

    true if a collision occurs, false otherwise.

  • Checks if the entity collides with a tile.

    Parameters

    • tileId: number

      The ID of the tile to check collision with.

    • pos: Vector

      The position of the entity.

    Returns boolean

    True if the entity collides with the tile, false otherwise.

  • Checks if the entity collides with a tile using raycasting.

    Parameters

    • tileId: number

      The data of the tile to check collision with.

    • pos: Vector

      The position of the entity.

    Returns boolean

    True if the entity collides with the tile, false otherwise.

  • Draws the entity on the screen if it is visible and within the screen bounds. If the entity has a tile object, it draws the tile object with the specified transformations. Otherwise, it draws the entity's sprite. If the game is in debug mode, it also displays debug information.

    Returns void

  • Gets the current animation frame of the entity. If the sprite is defined, it returns the animation frame of the sprite. Otherwise, it returns 0.

    Returns number

    The current animation frame.

  • Returns the relative bounding rectangle of the entity. The relative bounding rectangle is calculated by translating the entity's bounding rectangle and moving it based on the position of the scene's camera.

    Returns Box

    The relative bounding rectangle of the entity.

  • Returns the translated position rectangle of the entity. The translated position rectangle is calculated based on the entity's position in the scene.

    Returns Box

    The translated position rectangle of the entity.

  • Checks if the entity is overlapping with a given position and size.

    Parameters

    • pos: Vector

      The position vector of the other object.

    • size: Vector = ...

      The size vector of the other object.

    Returns boolean

    True if the entity is overlapping with the other object, false otherwise.

  • Checks if the entity is currently on the screen.

    Returns boolean

    True if the entity is on the screen, false otherwise.

  • Sets the animation for the entity.

    Parameters

    • animation: Animation

      The animation to set.

    • flipH: boolean = false

      (Optional) Whether to flip the animation horizontally. Default is false.

    • flipV: boolean = false

      (Optional) Whether to flip the animation vertically. Default is false.

    Returns void

  • Sets the animation frame for the entity's sprite.

    Parameters

    • frame: number

      The frame number to set.

    Returns void