Class ComponentAbstract

Base class for your game. Mostly everything in TypeSprite-games will be a component.

Simple example:

import {prop, component} from 'typesprite'

export class MyPlayer extends Component {

_@prop('number', 100) // NOTE: this needs to be @prop and not _@prop
private life:number;

onInit() {
// only called once when the entity is created.
}

onUpdate(detlaTime:number) {
// move your player
}

}

This class is tightly coupled with Entity and World:

  • A Component is part of an Entity.
  • An Entity is part of a World
  • A World is part of the WorldManager

So one or more worlds run. Each worlds contains one or more entities. Each entity has at least one Component. Every Entity is part of the life cycle and so are the components.

As a game developer you can access the outer world:

this.entity;         // access to the entity the component is part of
this.world; // access to the world the entity of the component is part of
this.world.manager; // access to the world manager that handles all worlds

Here an example

import {prop, component} from 'typesprite'

export class MyPlayer extends Component {

_@prop('number', 100) // NOTE: this needs to be @prop and not _@prop
private life:number;

onUpdate() {
if (this.life <= 0)
this.died();
}

died():void {
this.world.spawn("bomb"); // Spawn a bomb (another entity).
this.word.manager.getWorldByName("userInterface").sendMessage('died') // notify the UI
this.entity.dispose(); // Destroy's the players game object
}
}

See

  • Entity
  • World
  • WorldManager

Hierarchy

Constructors

Properties

entity: Entity = null

Accessors

Methods

  • A reference to another entity's component.

    It'll internally search the current world for the given entity + component and keep and check the reference.

    The idea is to keep the reference as a variable. This avoids ugly search code in the component space.

    Type Parameters

    Parameters

    • cmpName: string
    • Optional activesOnly: boolean
    • Optional entityName: string

    Returns ComponentRef<T>

Generated using TypeDoc