gpt4 book ai didi

android - 如何在 corona sdk 中移动对象?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:12 25 4
gpt4 key购买 nike

嘿,我正在使用这段代码在场景中移动(动画)我的对象但它会泄漏内存并停止响应。

//transition back
local function goBack( )
transition.to ( wall2, { time = 10000, x = 100, y = 310, onComplete = startTransition})
transition.to ( wall, { time = 10000, x = 700, y = 200, onComplete = startTransition})
transition.to (gate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition})
transition.to ( stargate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition})
end

//transition start
function startTransition( )
transition.to ( wall2, { time = 10000, x = 700, y = 310, onComplete = goBack})
transition.to ( wall, { time = 10000, x = 100, y = 200, onComplete = goBack})
transition.to ( gate_a, { time = 10000, x = 700, y = 255, onComplete = goBack})
transition.to ( stargate_a, { time =10000, x = 700, y = 255, onComplete = goBack})
end

startTransition()

如何在不泄漏任何内存的情况下正确移动对象?

最佳答案

这样做:

//transition back
local function goBack( )
transition.to ( wall2, { time = 10000, x = 100, y = 310})
transition.to ( wall, { time = 10000, x = 700, y = 200})
transition.to (gate_a, { time = 10000, x = 100, y = 255})
transition.to ( stargate_a, { time = 10000, x = 100, y = 255, onComplete = startTransition})
end

//transition start
function startTransition( )
transition.to ( wall2, { time = 10000, x = 700, y = 310})
transition.to ( wall, { time = 10000, x = 100, y = 200})
transition.to ( gate_a, { time = 10000, x = 700, y = 255})
transition.to ( stargate_a, { time =10000, x = 700, y = 255, onComplete = goBack})
end

startTransition()

由于所有持续时间都相同,因此无需在所有转换上调用 onComlpete。


如果需要,您可以取消函数内部的转换。为此,为转换分配一个名称,检查它是否仍在进行中,然后停止它。我给你举个例子。这不是强制性的,但如果您在执行上述代码后仍然内存力减退,您可以使用它。:

local trans_1,trans_2;
local function goBack( )
if(trans_1)then transition.cancel(trans_1) end -- to cancel an existing transition
trans_2 = transition.to ( wall2, { time = 10000, x = 100, y = 310})
end

function startTransition( )
if(trans_2)then transition.cancel(trans_2) end -- to cancel an existing transition
trans_1 = transition.to ( wall2, { time = 10000, x = 700, y = 310})
end

startTransition( )

继续编码................ 😃

关于android - 如何在 corona sdk 中移动对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16629202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com