1
我創造了我的遊戲中的雲,我想在20秒後刪除。問題是,當我添加代碼來刪除它們時,雲甚至不會出現,看起來它們在創建時就被刪除了。Corona SDK:延遲後刪除對象
這裏有兩種方法我試過已經(其中沒有工作):
local function removeBody(body)
body:removeSelf()
end
local function newCloud()
local n = cloudNumber
while n==cloudNumber do
n = math.random(1,5)
end
cloudNumber=n
local cloud = display.newImage(imageNames[cloudNumber], screenW+30, screenH*0.2)
timer.performWithDelay(6000, newCloud)
cloud.myName="cloud"
physics.addBody (cloud, {isSensor=true})
cloud:setLinearVelocity(-25,0)
cloud.gravityScale=0
timer.performWithDelay(20000,removeBody(cloud))
end
和
local function newCloud()
local n = cloudNumber
while n==cloudNumber do
n = math.random(1,5)
end
cloudNumber=n
local cloud = display.newImage(imageNames[cloudNumber], screenW+30, screenH*0.2)
timer.performWithDelay(6000, newCloud)
cloud.myName="cloud"
physics.addBody (cloud, {isSensor=true})
cloud:setLinearVelocity(-25,0)
cloud.gravityScale=0
--timer.performWithDelay(20000, cloud:removeSelf())
end
我該怎麼辦? 謝謝!
完美!謝謝! – dietbacon