@emile/engine / rendering/renderer / SpriteCreator
Class: abstract SpriteCreator
Defined in: src/rendering/renderer.ts:149
A sprite creator.
Sprite creators are used to create, update and delete sprites in the renderer.
If the sprite creator update method returns a ContainerChild, delete will be called and the returned ContainerChild will replace the old one.
Warning
Your create and delete methods are responsible for adding/removing the sprite from the world container. The renderer will not do this for you.
Extended by
Constructors
new SpriteCreator()
new SpriteCreator(
query?,overrideQueryEntities?):SpriteCreator
Defined in: src/rendering/renderer.ts:179
Creates a new sprite creator.
Parameters
query?
The query to match entities against.
overrideQueryEntities?
Set<string>
The override query entities to match against.
Returns
SpriteCreator
Properties
overrideQueryEntities?
readonlyoptionaloverrideQueryEntities:Set<string>
Defined in: src/rendering/renderer.ts:169
If set, this will override the query for this sprite creator.
Instead the sprite creator will run for all entities in this set.
This can also be useful for running a 'client only' sprite creator that doesn't use entities. You can instead fill the set with as many unique strings as you would like sprites. A good unique string would be Math.random().toString().substring(2, 15), this is almost guaranteed to be unique and not collide with any of your real entities.
DO NOT MODIFY THE SET AFTER CREATION.
query?
readonlyoptionalquery:EntityQuery
Defined in: src/rendering/renderer.ts:157
The query to match entities against.
The create, update and delete methods will only be called for entities that match this query.
If not set, the create, update and delete methods will be called for all entities.
Methods
create()
abstractcreate(data):ContainerChild
Defined in: src/rendering/renderer.ts:191
Creates a sprite in the renderer.
Parameters
data
The data for creating the sprite for the entity.
Returns
ContainerChild
The created sprite
delete()
abstractdelete(data,replacing):void
Defined in: src/rendering/renderer.ts:206
Deletes a sprite from the renderer.
Parameters
data
The data for deleting the sprite for the entity.
replacing
boolean
Returns
void
dispose()
abstractdispose():void
Defined in: src/rendering/renderer.ts:215
Dispose of the sprite creator.
Can be used to clean up any resources used by the sprite creator.
Called when the renderer is disposed.
Returns
void
emit()
emit(
event,data):void
Defined in: src/rendering/renderer.ts:264
Emits an event to all listeners.
Parameters
event
The event to emit.
data
The data to pass to the listeners.
Returns
void
Note
You don't need to call this method yourself unless you want to emit custom events. The renderer will automatically emit the CREATE, UPDATE, DELETE and DISPOSE events at the appropriate times.
off()
off(
event,callback?):void
Defined in: src/rendering/renderer.ts:239
Removes a listener for the given event.
If no callback is provided, all listeners for the event will be removed.
Parameters
event
The event to stop listening for.
callback?
The callback to stop listening for. If not provided, all listeners for the event will be removed.
Returns
void
on()
on(
event,callback):void
Defined in: src/rendering/renderer.ts:223
Adds a listener for the given event.
Parameters
event
The event to listen for.
callback
The callback to call when the event is fired.
Returns
void
update()
abstractupdate(data):void|ContainerChild
Defined in: src/rendering/renderer.ts:200
Updates a sprite in the renderer.
Parameters
data
The data for updating the sprite for the entity.
Returns
void | ContainerChild
The new created sprite