From 208e670c0e7c8b84469ad9a24f4972d47742130f Mon Sep 17 00:00:00 2001 From: Cazka Date: Sun, 13 Mar 2022 16:24:03 +0100 Subject: [PATCH] Making the entityManager an opt in option --- src/entity_manager.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/entity_manager.ts b/src/entity_manager.ts index a952261..02fd99e 100644 --- a/src/entity_manager.ts +++ b/src/entity_manager.ts @@ -14,6 +14,20 @@ class EntityManager { #entitiesUpdated: Entity[] = []; constructor() { + game.on('frame', () => { + this.#entities = this.#entitiesUpdated; + this.#entitiesUpdated = []; + }); + } + + get entities(): Entity[] { + return this.#entities; + } + + /** + * Calling this method is mandatory to start recording entities. + */ + initialize(): void { this.#triangleHook(); this.#squareHook(); @@ -24,15 +38,6 @@ class EntityManager { //when is a player being drawn? this.#playerHook(); - - game.on('frame', () => { - this.#entities = this.#entitiesUpdated; - this.#entitiesUpdated = []; - }); - } - - get entities(): Entity[] { - return this.#entities; } /**