-1

我目前正在 CoronaSDK (Lua) 中制作一个简单的应用程序,但我有一些问题:

  • 我想要一个计分器,但自从我做到了,我的应用程序就一直崩溃。
  • 我不知道如何制作一个“好”的分数计数器。一些帮助将不胜感激。:)

代码:

function points(num)
    tmr = timer.performWithDelay(1000, points, 0)
    num = 5
    score = 2
    score = score + num
    scoreTxt.text = "score: " .. score
    scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
    scoreTxt.x = screenLeft + 15
end

真的不知道要放timer.cancel(tmr)

function explode()
    timer.cancel(tmr)
    explosion.x = jet.x
    explosion.y = jet.y
    explosion.isVisible = true
    explosion:play()
    jet.isVisible = false   
    timer.performWithDelay(3000, gameOver, 1)
end

function onCollision(event)
    if event.phase == "began" then
        if jet.collided == false then
            timer.cancel(tmr)
            num = nil;
            score = nil;
            jet.collided = true 
            jet.bodyType = "static"

            explode()
        end
    end
end   

更多信息不知道您是否需要它:P

score = 1.5;
num = 1;
scoreTxt = display.newText ("Score:", 0, 0, "Helvetica", 20)
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 10
scoreTxt.y = display.screenOriginX + 5
screenLeft = display.screenOriginX

如果有人可以帮助我,我将非常感激 :) 在此先感谢

4

1 回答 1

1
tmr = timer.performWithDelay(1000, points, 0)

这一行 in points 函数可以进行无限的函数调用。这就是泄漏的原因。如果你想每秒调用点函数,你应该从其他地方调用它。

于 2013-10-16T12:44:42.227 回答