2014-07-15 7 views
3

我經歷了一些幫助,並在屏幕退出時刪除了所有變量,計時器和事件監聽器。但我仍然面臨同樣的問題,也就是我第一次玩遊戲時,它的工作正常,當我重玩遊戲時,它的速度本身和應用程序最終崩潰。當我重放遊戲時,它的速度從之前的速度增加,遊戲在Android平臺的暈眩sdk中墜毀

我在遊戲中添加了一些障礙,因此發生了。所以當我把它們作爲評論時,它的工作很好。 我在這裏添加這些變量: -

------------------------ 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 

+0

考慮添加你正在使用的平臺(android?)到標籤列表。電暈標籤本身可能不會生成許多視圖。 – Sharagoz

+0

是的,我在使用註釋的時候在我的代碼中工作的Android平臺 – Sangu

+0

,然後它的工作正常。如果我刪除評論,然後其速度增加在下一個答覆 – Sangu

回答

1

我終於解決了這個問題。這個問題不在我上面顯示的代碼中,只是暫時解決了這個問題。但同樣的問題又出現了。此問題的解決方案試圖刪除並取消所有addEventListener和timer.performWithdelay,這只是這些類型問題的解決方案。在開始時,我們可能無法識別,但是當我們嘗試我們的代碼在沒有此功能的情況下運行時,我們可以輕鬆識別出這是唯一的問題,並通過逐個刪除所有事件監聽器和取消計時器來解決我們的問題