2013-06-26 36 views
0

我正在製作一個簡單的「breakout」遊戲,並且我有重新加載map的問題。例如:如果我從level1開始,打破一些磚塊並丟失,比我再次加載相同的地圖。接下來的那個球與同磚我「感動」碰撞時間之前,都會給我一個錯誤Attempt to remove an object that has already been removedCorona「嘗試移除已被移除的物體」

local map = lime.loadMap("maps/" .. currentLevel .. ".tmx") 
local layer = map:getTileLayer("bricks_1") 
local visual = lime.createVisual(map) 
local physical = lime.buildPhysical(map) 


function removeBricks(event) 
    if event.other.isBrick then 
     local brick = event.other 
     transition.to(brick, {time = 20, alpha = 0}) 

     score = score + brick.scoreValue 
     ScoreNum.text = score 

     -- remove brick 
     brick:removeSelf() 
     brick = nil 
     ... 
+0

請寫你的錯誤代碼行。 – vovahost

回答

0

我認爲event.other未創建你去你的遊戲第二次您使用的故事板,如果這樣你就可以嘗試後,遊戲就結束了,所以當你去你的遊戲再次刪除場景它將重新創建所有對象

0

你試試這個?

transition.to(brick, {time = 20, alpha = 0, onComplete = function() 
    if brick then 
     brick:removeSelf() 
     brick = nil 
    end 
end}) 
0

如果您正在使用物理,您還必須先執行一個physics.removeBody(brick),然後才能刪除該對象本身,以便從物理引擎中分離出來。如果物理學不認爲它仍然存在。