iphone - Application starts going nuts after a while -


i've started using corona sdk , i'm trying build app iphone. main idea behind it, there birds flying , have shoot them. birds random spot on screen target, , navigate towards it. app runs fine 30 secs - 1 minute, starts speeding enormously fast , don't know why.

and regarded appreciated.

display.setdefault("background", 246, 255, 100) _w = display.contentwidth; _h = display.contentheight; target = {} birdposition = {} print(_w.." ".._h)  --getting random location on screen local x = math.random(_w) local y = math.random(_h)  --this checks whether image placed partially off screen if x > _w - 42     x = _w - 42 end if y > _h - 42     y = _h - 42 end  birdposition[1] = x birdposition[2] = y local equation = 0 --will used see whether movement more vertically horizontally local movevertically = false local bird = display.newimage("images/bird.png", x, y) --when bird touched, removed function bird:touch()     bird:removeself() end  bird:addeventlistener("touch", bird) --get new random position function getnewposition()     --loop = 50     --getting random next spot move + check     x = math.random(_w)     y = math.random(_h)     if x > _w - 42         x = _w - 42     end     if y > _h - 42         y = _h - 42     end     --placing co-ordinates     target[1] = x     target[2] = y     local smallest     birdposition[1] = bird.x     birdposition[2] = bird.y     local diffy     --this check done positive equation     if x > bird.x         diffx = x - bird.x     else         diffx = bird.x - x     end     if y > bird.y         diffy = y - bird.y     else         diffy = bird.y - y     end     --this check done equation bigger 1. checks     --whether move more vertically horizontally putting boolean true or false     if diffx >= diffy         equation = diffx/diffy         smallest = diffy         movevertically = false     else         equation = diffy/diffx         smallest = diffx         movevertically = true     end      --print("birdposition x: "..birdposition[1].. " birdposition y: "..birdposition[2])     --print("target x: " .. target[1].." target y: "..target[2])       --[[     if instance diffx = 100 , diffy = 50:     smallest 50, because move vertically , have executed 50 times give effect flies quick ]]--     tmr = timer.performwithdelay(10, movebird, smallest) end  function movebird()     if movevertically == true         if target[1] >= birdposition[1]             bird.x = bird.x + 1         else              bird.x = bird.x - 1         end         if target[2] >= birdposition[2]             bird.y = bird.y + equation         else             bird.y = bird.y - equation         end     else         if target[1] >= birdposition[1]             bird.x = bird.x + equation         else              bird.x = bird.x - equation         end         if target[2] >= birdposition[2]             bird.y = bird.y + 1         else             bird.y = bird.y - 1         end     end     --print("bird x: "..bird.x .. " bird y: " .. bird.y)      --this checks every possibility new position     if bird.x == target[1] or bird.y == target[2] or bird.y < 0 or bird.x > 640 or bird.x < 0 or bird.y > 960          getnewposition()     end end      getnewposition() 

one error in timer.performwithdelay(10, movebird, smallest).

the timer not called correct way: third argument should number of iteration (so 1), , not smallest.

see doc here


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -