WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP
Building blocks in the ECS.
Components must have arg-less constructors or no constructors at all. (They will be auto-added)
All initialized fields are initialized in an auto-generated private function __defaultInit(args...)
.
See example below.
You can also add an init function in the form: public function init(args...)
init
gets called when a component is added or recycled.
If no init
is defined, it will be auto-generated to call __defaultInit
.
You can also mark fields to be included as optional args in init
and __defaultInit
using the meta tag @:initArg
.
If the arg is null
, then it will be default initialized to your expr.
This means you can write a pure component where you only define fields and default values.
You can also add component dependencies using @:require(<Components...>)
on the class.
When the component is added, it's dependencies are auto-added if not added yet.
@:require(kappa.Transform)
class Foo implements IComponent
{
@:initArg public var x = 5;
public var y = 4.2;
// the following are auto-generated
public function new() {}
inline private function __defaultInit(?_x:Int)
{
x = _x == null ? 5 : _x;
y = 4.2;
}
public function init(?_x:Int)
{
__defaultInit(_x);
}
}
To add a component to an entity, just call:
world.add(e, ThisComponent, args...)
where args...
are the arguments for init
.