X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=engine%2Fspawned_entity.js;fp=engine%2Fspawned_entity.js;h=bdc5153469cfec9df22250710c53c5ca87744395;hb=47936b8e792d2dbd2db6c402c919283f5dd5e074;hp=47969059010b806a628d804337f73897193f60e9;hpb=d77ddb4d312f9428a6167a56bd17a0013441df87;p=dragonblocks.git 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);