设备上的应用与模拟器上的应用不同。

我已经完成了我的应用程序,在 Corona 模拟器上运行得非常出色,但是一旦我在设备上运行它,就不能运行一堆指令。

这些是:

function onCollision( event )
    if ( event.phase == "began" ) then
        if event.object1.myName == "ground" and event.object2.myName == "spaceShip" then

                local a = score.get()
                print(a)
                local b = score.load()
                print(b)

                if (a < b) then
                    best.alpha = 1

                    scoreToBeat.text = score.load()
                    scoreToBeat.alpha = 1

                else
                    score.save()
                    newRecord.alpha = 1
                end

                timer.cancel(tmrScore)
                gameOver.alpha = 1
                tapToReplay.alpha = 1
                replay.alpha = 0.01
                fade.alpha = 0
                timer.cancel(tmrIS)
                spaceShip.alpha = 1
                if(playEffects) then
                    media.playEventSound( "sounds/gameover.mp3" )
                    playEffects = false
                end
                speed = 0

     end
    end
  end

 Runtime:addEventListener( "collision", onCollision )

特别是它只执行 "speed = 0",而且只有第一次运行应用程序时才执行,这意味着如果我开始新游戏,甚至都不会执行 "speed = 0"。

我百分之百确定在设备上运行的应用程序与模拟器上运行的应用程序相同(我尝试更改一些文本)。

我该怎么办?

点赞
用户869951
用户869951

可能有多种原因:物理学没有在场景回到时启动;物体不是动态的;它们中的一个不再存在或不再是物理对象;当游戏结束并且未重新启动时,处理程序被移除。

为了找出原因,添加一些打印语句以查看哪些部分执行:

function onCollision( event )
    print 'entered collision'
    if ( event.phase == "began" ) then
        print 'collision began'
        if event.object1.myName == “gd” and event.object2.myName == “hero” then
            print 'collision objects are gd and hero'

            speed = 0

            if (score.get() < score.load()) then
                print 'score smaller'
                ...

            else
                print 'score not smaller'
                ...

            end
        else
             print( 'collision objects are', event.object1.myName, event.object2.myName )
        end
    end
end

更新:

我有一个笔误,score = 0,应该是 speed = 0

2014-04-02 17:20:57