Lua 如何使用Corona SDK有效地处理对象的删除?
我有一个按钮,每次触摸按钮时都会产生并施加力。 如何防止内存泄漏 我正在使用director类从一个场景切换到另一个场景。 代码如下:Lua 如何使用Corona SDK有效地处理对象的删除?,lua,coronasdk,Lua,Coronasdk,我有一个按钮,每次触摸按钮时都会产生并施加力。 如何防止内存泄漏 我正在使用director类从一个场景切换到另一个场景。 代码如下: -- Fire the rocket from the jet position local function fireTheRocket(event) if event.phase == "ended" then local fireBall = display.newImage( "rocket.png") fireBall.
-- Fire the rocket from the jet position
local function fireTheRocket(event)
if event.phase == "ended" then
local fireBall = display.newImage( "rocket.png")
fireBall.x = jet.x;
fireBall.y = jet.y;
GUI:insert(fireBall);
physics.addBody(fireBall, "dynamic")
fireBall:applyForce( 1000, 0, fireBall.x, fireBall.y )
end
end
fireBtn:addEventListener("touch", fireTheRocket)
您可以尝试这样做: (施加力后插入)
它会在1秒后摧毁你的火箭。或者,如果你想在它与其他对象碰撞时销毁它,你也可以这样做。我的意见是将此图像添加到一个数组中。设置计时器可删除数组中的子图像。
local function DestroyRocket()
fireBall:removeSelf()
fireball = nil
end
timer.performWithDelay( 1000, DestroyRocket)