diff --git a/main.lua b/main.lua index 5f9f778..43215d5 100644 --- a/main.lua +++ b/main.lua @@ -121,6 +121,7 @@ function gotoRoom(room_type, ...) if type(Class) ~= "table" and type(Class) ~= "function" then error("room '"..room_type.."' is not callable (got "..type(Class)..", does room return itself?)") end + if current_room and current_room.destroy then current_room:destroy() end current_room = _G[room_type](...) end diff --git a/obj/Room.lua b/obj/Room.lua index f945190..056c0c1 100644 --- a/obj/Room.lua +++ b/obj/Room.lua @@ -46,4 +46,10 @@ function Room:canvasDraw() self.area:draw() end +---Destroys room +function Room:destroy() + self.area:destroy() + self.area = nil +end + return Room