Base class for your game. Mostly everything in TypeSprite-games will be a component.
Simple example:
import {prop, component} from'typesprite'
exportclassMyPlayerextendsComponent {
_@prop('number', 100) // NOTE: this needs to be @prop and not _@prop privatelife: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'
exportclassMyPlayerextendsComponent {
_@prop('number', 100) // NOTE: this needs to be @prop and not _@prop privatelife: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 } }
Base class for your game. Mostly everything in TypeSprite-games will be a component.
Simple example:
This class is tightly coupled with Entity and World:
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:
Here an example
See