当我重播游戏时,它的速度从之前的速度增加,游戏在电晕版SD中崩溃,用于Android平台

时间:2014-07-15 13:16:30

标签: android lua corona

我经历了一些帮助,并在屏幕退出处删除了所有变量,计时器,事件监听器。但是我仍然面临同样的问题,即我第一次玩游戏,它的工作正常,当我重播游戏时,它的速度会自动增加,应用程序最终崩溃。

我在游戏中添加了一些障碍,因为它发生了。因此,当我将它们作为评论时,它的工作正常。 我在这里添加这些变量: -

------------------------ CREATE BIRDS --------------------- -------

            currentXLocObstacleBird = currentXLocObstacleBird - SCREEN_WIDTH      
    while (currentXLocObstacleBird < SCREEN_WIDTH) do
        obstacleType = math.random(4)
        local  birdHeight = math.random(display.topStatusBarContentHeight + 200, display.contentHeight - 200)
        if (obstacleType % 2 == 0) then  -- one in two chance of displaying a each of the snake
            obstacleType = mathDiv(obstacleType, 2)                
            if (obstacleType == 1) then
                obstacles_Variables.imgBirdY = display.newSprite( otherSpriteSheet , birdSequenceData2)
                obstacles_Variables.imgBirdY:play()
                if (a == 1) then  -- if it is for first screen then start from zero otherwise start from loc+screnwidth ie. second screen
                    obstacles_Variables.imgBirdY.x = currentXLocObstacleBird
                    birdYPolygon = display.newPolygon(currentXLocObstacleBird, birdHeight, {0,20, 50,0, 115,50, 50,40 })
                else
                    obstacles_Variables.imgBirdY.x = currentXLocObstacleBird + SCREEN_WIDTH
                    birdYPolygon = display.newPolygon(currentXLocObstacleBird + SCREEN_WIDTH, birdHeight, {0,20, 50,0, 115,50, 50,40 }) -- birdShape)
                    physics.addBody(birdYPolygon, "static",{density = 0, bounce = 0, friction = 0 })                        
                end 
                obstacles_Variables.imgBirdY.y = birdHeight
                obstacles_Variables.imgBirdY.name = "yelloBird1" 
                obstacles_Variables.imgBirdY.screenIndex = a     -- indicates which screen this object belongs to (from SCREENS_PER_LEVEL)
                obstacles_Variables.imgBirdY.isVisible = false
                obstacles_Variables.imgBirdY.speed = Speed_Constant_Array.SPEED_BIRD_1
                obstacles_Variables.imgBirdY:rotate(15)                    
                groupObstacles:insert(obstacles_Variables.imgBirdY)                    
--                    birdYPolygon.name = "yelloBird"
--                    birdYPolygon.screenIndex = a
--                    birdYPolygon.isVisible = false
--                    birdYPolygon.speed = Speed_Constant_Array.SPEED_BIRD_1
--                    groupObstacles:insert(birdYPolygon)
                currentXLocObstacleBird = currentXLocObstacleBird + 2 * WIDTH_YELLOW_BIRD    

            elseif(obstacleType == 2) then
                obstacles_Variables.imgBirdG = display.newSprite( otherSpriteSheet , birdSequenceData)
                obstacles_Variables.imgBirdG:play()
                if (a == 1) then  -- if it is for first screen then start from zero otherwise start from loc+screnwidth ie. second screen
                    obstacles_Variables.imgBirdG.x = currentXLocObstacleBird
                   birdGPolygon = display.newPolygon(currentXLocObstacleBird, birdHeight, {0,20, 50,0, 115,50, 50,40 }) --birdShape2)
                else
                    obstacles_Variables.imgBirdG.x = currentXLocObstacleBird + SCREEN_WIDTH 
                    birdGPolygon = display.newPolygon(currentXLocObstacleBird + SCREEN_WIDTH, birdHeight, {0,20, 50,0, 115,50, 50,40 }) --birdShape2)
                    physics.addBody(birdGPolygon, "static",{density = 0, bounce = 0, friction = 0 })                    
                end
                obstacles_Variables.imgBirdG.y = birdHeight
                obstacles_Variables.imgBirdG.name = "greenBird1"
                obstacles_Variables.imgBirdG.screenIndex = a     -- indicates which screen this object belongs to (from SCREENS_PER_LEVEL)
                obstacles_Variables.imgBirdG:rotate(15)
                obstacles_Variables.imgBirdG.speed = Speed_Constant_Array.SPEED_BIRD_2
                obstacles_Variables.imgBirdG.isVisible = false
                groupObstacles:insert(obstacles_Variables.imgBirdG)

--                    birdGPolygon.name = "greenBird"
--                    birdGPolygon.screenIndex = a     -- indicates which screen this object belongs to (from SCREENS_PER_LEVEL)
--                    birdGPolygon.isVisible = false
--                    birdGPolygon.speed = Speed_Constant_Array.SPEED_BIRD_2
--                    birdGPolygon:setFillColor(1,0,0,0)
--                    groupObstacles:insert(birdGPolygon)

                currentXLocObstacleBird = currentXLocObstacleBird + 2 *            WIDTH_GREEN_BIRD
            end                
        end
        currentXLocObstacleBird = currentXLocObstacleBird + math.random(500, 700)  -- add some spacing for the next decor
        end  

1 个答案:

答案 0 :(得分:1)

最后我解决了这个问题。如上所示,问题不在此代码中,这只是暂时解决的。但同样的问题又开始了。这个问题的解决方案是试图删除并取消所有addEventListener和timer.performWithdelay,这只是这类问题的解决方案。在开始时我们可能无法识别,但是当我们尝试运行没有此功能的代码时,我们可以很容易地确定这只是问题,通过逐个删除所有事件监听器和取消计时器也将解决我们的问题