From 47936b8e792d2dbd2db6c402c919283f5dd5e074 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 30 Jun 2021 14:49:41 +0200 Subject: [PATCH] Remove entities from old map when setting a new one --- engine/init.js | 2 +- engine/spawned_entity.js | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/engine/init.js b/engine/init.js index 44359e8..e8daae4 100644 --- a/engine/init.js +++ b/engine/init.js @@ -154,7 +154,7 @@ if (dragonblocks.loggedin) setTimeout(_ => { - dragonblocks.player.despawn(); + dragonblocks.player.removeFromMap(); dragonblocks.world.save(); location.reload(); }); diff --git a/engine/spawned_entity.js b/engine/spawned_entity.js index 4796905..bdc5153 100644 --- a/engine/spawned_entity.js +++ b/engine/spawned_entity.js @@ -72,10 +72,22 @@ dragonblocks.SpawnedEntity = class return dragonblocks.entities[this.name]; } + removeFromMap() + { + let self = this; + this.map.entities = this.map.entities.filter(entity => { + return entity != self; + }); + } + setMap(map, x, y) { - this.tmp.display = map.entityContainer.appendChild(this.display); + this.removeFromMap(); + map.entities.push(this); + this.tmp.map = map; + this.tmp.display = map.entityContainer.appendChild(this.display); + this.teleport(x, y); } @@ -84,10 +96,7 @@ dragonblocks.SpawnedEntity = class let entityDef = this.toEntity(); entityDef.ondespawn && entityDef.ondespawn(this); - let self = this; - this.map.entities = this.map.entities.filter(entity => { - return entity != self; - }); + this.removeFromMap(); clearInterval(this.physicInterval); clearInterval(this.tickInterval); -- 2.44.0