【问题标题】:How to move object in corona sdk?如何在 corona sdk 中移动对象?
【发布时间】:2013-05-18 21:36:08
【问题描述】:

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

//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()

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

【问题讨论】:

    标签: android iphone ios coronasdk


    【解决方案1】:

    这样做:

    //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( )
    

    继续编码...... ?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多