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

时间:2014-04-02 15:54:20

标签: android ios lua corona

我已经完成了我的应用程序,它在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 )

特别是,它只执行&#34; speed = 0&#34;并且只有我第一次运行应用程序,这意味着如果我开始一个新游戏,它甚至不会工作&#34; speed = 0&#34;。

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

我该怎么办?

1 个答案:

答案 0 :(得分:0)

可能有多种原因:物理学在回到现场时没有开始;对象不是动态的;其中一个不再存在或不再是物理对象;游戏结束时没有重新启动处理程序。

要弄清楚,请添加一些打印语句以查看执行的部分:

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