Private
Readonly
_activesPrivate
Readonly
_alwaysPrivate
Readonly
_deactivesPrivate
_entityPrivate
_entityPrivate
_factoryPrivate
Readonly
_newPrivate
Readonly
_onPrivate
_pendingPrivate
_resettingPrivate
_stateReadonly
managerReadonly
namePrivate
staticReadonly
staticsPrivate
Readonly
worldPrivate
loadingPrivate
activatereturns null or first entity matching name
complete name of the entity. must match exactly
if false one can also search for deactive entities
if true also entities in preparation are searched (useful during initialization)
old name
spawnInstance
use spawnInstance instead
Private
injectPrivate
internPrivate
internPrivate
internCreates new entity(ies) and inject it as a new instance into the management process.
This function will return when
If the data is already loaded than it'll return instantly.
If the entity cannot be created a error is sent to the logger.error function. OnReady will still be called.
Private
internPrivate
internPrivate
orderMain function to inject new entities into the running world.
export class MyPlayer extends Components {
@child("Bomb") // this makes sure all resources are loaded for the bomb
private bomb:string;
onUpdate(t:number):void {
if (playerWantsToThrowBomb) {
// new bomb is created!
this.world.spawn(this.bomb);
}
if (playerWantsToThrowBigBomb) {
// overwrite power property for this instance!
this.world.spawn(this.bomb, {power: 200});
}
}
}
NOTE: For spawning objects to load a level use
beforeWorldStart(loader:WorldStartContext)
instead.
entity definition name in the current world
Optional
props: Record<string, any>set/overwrite property
Optional
instanceName: stringSame as spawn
but with an object.
spawn
This will start the world.
That means:
beforeWorldStart(...)
of static entities' componentsbeforeWorldStart(...)
As those steps can take more than one frame to perform it won't just start. Instead it first goes into loading-state (see getState() == WorldState.Loading)
Generated using TypeDoc
A world is managed and instantiated by the WorldManager.
Each world is a running, breathing entity-component group that is created out of an EDF file. The EDF defines all instances that can be created within this world and also set's the list of static entities.
Static entities are instantiated on startup are meant to populate the rest of the world.
Using dependency information it is possible to ensure a static entity creation order. That way those entities that others rely on can be created first.
It is possible to access entities or other worlds by query for the ID of other worlds. Messages can be sent and information can find it's way.
Life-Cycle
A world has multiple states which can be manipulared by the following functions:
Basically the idea is to call activate() when you want to run the/a level or game part. If a world is finished and we don't need the world for now we call clear(). To restart a level and set everything to start we use reset(). Pause and Resume change the
enabled
flag and help to pause things that we currently don't need to run but like to continue later.Loading & Reloading
Every call of
stop()
will not just stop the world but also release all resources. This is good if the world represents something that isn't needed anymore. However, imagine the world reperesents a running level of a Jump&Run and you like to stop/start it whenever the player dies. In such a case you want to keep all resources and reuse them. In such a case it's better to userestart()
.Using
restart()
will only unload resources that are not needed after the start anymore and load the ones that are missing. This is only true if the same resource isn't referenced in another active world.If this automatic approach does not work for you it's also possible to create a world only for the purpose of loading certain resources. This means a world can also be understand as resource managing object.
Rendering
Normally entities only get the onUpdate call so they can do the mainloop things. If one likes to write an entity that shall receive the render event one must call receiveFrameUpdates().