diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-12 17:58:31 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-12 17:58:31 +0800 |
| commit | 33cf1a9f7fe9a87923db11f8d1e2a7cf756a690a (patch) | |
| tree | 8f7f23eb52ca2b06797254378240bec947802c91 /objects | |
| parent | 85601ce710290a11b936e0b175a870babebcd85c (diff) | |
refactor: use lifecycle manager to destroy all bodies
Diffstat (limited to 'objects')
| -rw-r--r-- | objects/Enemy.lua | 2 | ||||
| -rw-r--r-- | objects/Loot.lua | 2 | ||||
| -rw-r--r-- | objects/Shot.lua | 2 | ||||
| -rw-r--r-- | objects/room.lua | 4 |
4 files changed, 5 insertions, 5 deletions
diff --git a/objects/Enemy.lua b/objects/Enemy.lua index 2ab24b8..9c28c3c 100644 --- a/objects/Enemy.lua +++ b/objects/Enemy.lua @@ -120,7 +120,7 @@ function Enemy:die() end local enemies = G.currentRoom.objects.enemies - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) table.remove(enemies, utils.indexof(enemies, self)) end diff --git a/objects/Loot.lua b/objects/Loot.lua index 9c272a1..b7ea2c5 100644 --- a/objects/Loot.lua +++ b/objects/Loot.lua @@ -23,7 +23,7 @@ function Loot:onContact(other) if other.objectType == "player" then local pickedLoot = table.remove(loots, utils.indexof(loots, self)) table.insert(G.player.hearts, pickedLoot.type) - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) end end diff --git a/objects/Shot.lua b/objects/Shot.lua index 3a07a7b..67caadd 100644 --- a/objects/Shot.lua +++ b/objects/Shot.lua @@ -37,7 +37,7 @@ end function Shot:die() local shots = G.currentRoom.objects.shots table.remove(shots, utils.indexof(shots, self)) - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) end function Shot:onContact(other, contact) diff --git a/objects/room.lua b/objects/room.lua index 39552bc..3415660 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -245,11 +245,11 @@ end function Room:removeAllBodies() for _, group in pairs(self.objects) do for _, obj in ipairs(group) do - obj.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(obj.physicsBody) end end for _, wall in ipairs(self.walls) do - wall.body:destroy() + G.BodyLifeCycleManager:destroy(wall.body) end end |
