Options
All
  • Public
  • Public/Protected
  • All
Menu

An entity with additional properties for collision testing and display.

Example

// A 32x32 image is loaded into a texture, then the sprite
// is created from that texture
const texture = new Texture('assets/images/bullet.png')
const bullet = new Sprite(texture)

// Can also be combined into one line, e.g.
// const bullet = new Sprite(new Texture('assets/images/bullet.png'))

// Properties can then be set on the sprite.
bullet.hitBox.set(4, 2, 16, 12)
bullet.anchor.set(16, 16)

Hierarchy

Index

Constructors

constructor

Properties

alpha

alpha: number

The opacity of the entity (from 0 to 1)

children

children: Partial<Entity>[]

An array of child entities for recursive update/render.

dead

dead: boolean

Whether or not the entity is dead.

hitBox

hitBox: HitBox

The hitbox of the sprite.

pos

pos: Vec

Position of the entity.

rotation

rotation: number

The rotation of the sprite.

scale

scale: Vec

Scale of the entity.

visible

visible: boolean

Whether or not the entity is visible.

Accessors

anchor

  • get anchor(): Vec

hasChildren

  • get hasChildren(): boolean

height

  • get height(): number
  • set height(value: number): void
  • Gets the height of the sprite in pixels, accounting for scale.

    Returns number

  • Sets the height.

    Parameters

    • value: number

    Returns void

pivot

  • get pivot(): Vec

texture

width

  • get width(): number
  • set width(value: number): void
  • Gets the width of the sprite in pixels, accounting for scale.

    Returns number

  • Sets the width.

    Parameters

    • value: number

    Returns void

Methods

add

  • add<T>(child: T): T
  • Add and return a child object.

    Type parameters

    • T

    Parameters

    • child: T

      Object to add to the container.

    Returns T

map

  • map(fn: (child: Partial<Entity>, index?: number) => void): any
  • Map a function across all children.

    Parameters

    • fn: (child: Partial<Entity>, index?: number) => void

      Function to call for each child.

        • (child: Partial<Entity>, index?: number): void
        • Parameters

          • child: Partial<Entity>
          • Optional index: number

          Returns void

    Returns any

remove

  • remove<T>(child: T): T
  • Remove and return a child object.

    Type parameters

    • T

    Parameters

    • child: T

      Object to remove from the container.

    Returns T

update

  • update(_: number, __: number): void