javascript-entity-component-system
javascript-entity-component-system copied to clipboard
Add a deltatime variable to the update cycle
Pretty basic thing, yet not implemented. A deltatime variable in the ECS.update()
method should be added to get rid of inconsistent frames.
I would suggest just passing the down to the processor which the update function (the one the user writes) can safely use.
update(entity: Entity, components: Component[], processor: Processor, deltaTime: number) {
const [position, mass] = components
const gravity = 2
const result = mass.state.mass * gravity * deltaTime
mass.state.velocityY += result
position.state.y += mass.state.velocityY
}
A thing that annoys me a bit here, is the amount of arguments that the update function gets, when being called. I didn't like it before and now it looks even worse. I've added the entity
and processor
variables as a way to query/change things on edge cases but I don't know if they are actually really needed. People could just query the ECS class if they need it tbh.