Closed GGAlanSmithee closed 5 years ago
Work-around until fixed:
const comp = 'comp'
class Component {
constructor(x, y) {
this.x = x
this.y = y
}
x = 0
y = 0
}
entityManager.registerComponent(comp, Component)
const entities = entityManager
.build()
.withComponent(comp, () => { return new Component(10, 5) })
.create(3)
However, the below code (without a initializer) will fail, so this still needs to be fixed (preferably without the function returning a new instance hack)
const entities = entityManager
.build()
.withComponent(comp)
.create(3)
This has been fixed in the dev branch. On top of this, the initialization API was changed to always require a function, to keep the API normalized.
Example:
entityManager.withComponent('myComp', () => new MyComp(12, 'hi'))
crashes here