| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- class UserComponent {
- /**
- * @param gameObject The entity.
- */
- constructor(gameObject: Phaser.GameObjects.GameObject) {
- this.scene = gameObject.scene;
- const listenAwake = this.awake !== UserComponent.prototype.awake;
- const listenStart = this.start !== UserComponent.prototype.start;
- const listenUpdate = this.update !== UserComponent.prototype.update;
- const listenDestroy = this.destroy !== UserComponent.prototype.destroy;
-
- if (listenAwake) {
- gameObject.once("components-awake", this.awake, this);
- }
- if (listenStart) {
- this.scene.events.once(Phaser.Scenes.Events.UPDATE, this.start, this);
- }
- if (listenUpdate) {
- this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this);
- }
- if (listenStart || listenUpdate || listenDestroy) {
- gameObject.on(Phaser.GameObjects.Events.DESTROY, () => {
- this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.start, this);
- this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.update, this);
- if (listenDestroy) {
- this.destroy();
- }
- });
- }
- }
- scene: Phaser.Scene;
- protected awake() {
- // override this
- }
- protected start() {
- // override this
- }
- protected update() {
- // override this
- }
- protected destroy() {
- // override this
- }
- }
|