Actors (and maybe other classes) expose methods such as onPreUpdate or onCollisionStart as convenient handlers for events to avoid manually wiring up to events.
However, the method signature is different than what you would get if you did manually wire up to the event.
// method on Actor
class Player extends ex.Actor {
onPreUpdate(engine: Engine, delta: number) {}
}
// wiring up to event manually e.g. when extending Entity
class Player extends ex.Entity {
constructor() {
super()
this.on('preupdate', this.onPreUpdate)
}
onPreUpdate({ engine, delta }: ex.PreUpdateEvent) {}
}
This makes it inconvenient if I want to move code around in such a way that i'm going to/from an event handler/class method.
Proposal
This is a severely breaking change
Align all onXYZ convenience methods to use event as the parameter rather than multiple parameters from the event.
class Player extends ex.Actor {
onPreUpdate({ engine, delta }: ex.PreUpdateEvent) {}
}
Context
Actors (and maybe other classes) expose methods such as
onPreUpdate
oronCollisionStart
as convenient handlers for events to avoid manually wiring up to events.However, the method signature is different than what you would get if you did manually wire up to the event.
This makes it inconvenient if I want to move code around in such a way that i'm going to/from an event handler/class method.
Proposal
This is a severely breaking change
Align all onXYZ convenience methods to use event as the parameter rather than multiple parameters from the event.