-
Notifications
You must be signed in to change notification settings - Fork 1
Components
Dimitri Pomier edited this page Oct 20, 2021
·
5 revisions
Since alpha.6
, ecso
supports the following metadata annotations on abstract fields:
-
@:ecso.added
: invokes the annotated method when added to an entity. -
@:ecso.removed
: invokes the annotated method when removed from an entity.
When considering the following archetype:
typedef MyArchetype = {
name:MyComponent
}
abstract MyComponent(String} from String {
@:ecso.added function onAdded() {
trace( this + ' added' );
}
@:ecso.removed function onRemoved() {
trace( this + ' removed' );
}
}
- The method
onAdded
is triggered from a creation or a mutation:
entities.createEntity(({
name: "Foo"
}:MyArchetype));
// or
entities.foreachEntity(function(entity:MyArchetype) {
entity.name = "Bar";
});
- The method
onRemoved
is triggered from a deletion or a mutation:
entities.foreachEntity(function(entity:MyArchetype) {
entities.deleteEntity(e);
});
// or
entities.foreachEntity(function(entity:MyArchetype) {
entity.name = null;
});
Home | Getting Started | Entities
| Components
| Systems
| Contexts
| Archetypes
| Slack | Contribute