-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Events are an important part of any game, and it's only natural to want them for ECS programming. There are plenty of situations where you'll want to know about new components being added and old ones being removed. foreachEntity is good, but can't do everything.
My suggestion is to add two new functions to EntityGroup: onEntityMatched (calls a function when an entity begins to match an archetype) and onEntityUnmatched (calls a function when an entity stops matching an archetype). Here's an example of how they might look in action:
entities.onEntityMatched( function (entity:{ display:DisplayObject }) {
stage.addChild(entity.display);
} );
entities.onEntityUnmatched( function (entity:{ display:DisplayObject }) {
stage.removeChild(entity.display);
} );
var entity = {};
entities.createEntity(entity);
entity.display = Images.get("BeachBall.png"); //The image is automatically added to the stage.
entity.display = null; //The image is automatically removed from the stage.Note that both systems need to know the value of display. Thus onEntityMatched has to run after setting the new value, but onEntityUnmatched has to run before.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels