Hey guys, to keep things sweet and simple, what Im trying to do is make a value called “Obstacles” and to increase it by 1 per each object that scrolls off screen on X axis.
The problem that happens is that either 1 object increments 1 every second its off screen which results in a huge number for just 1 obstacle dodged. is it that it is still scrolling even off screen? if so how can I remove the block individually or just increment by 1 only?
thanks
Here is how its set up:
local obstacles = 0 local yPos = {50,110,200} function updateNum( event ) obstacles = obstacles + 1 end unction createBlock(event) local rnd = math.floor(math.random() \* 4) + 1 b = display.newImage('images/block3.png', display.contentWidth, yPos[math.floor(math.random() \* 3)+1]) b.name = 'block' physics.addBody(b, "static") blocks:insert(b) end function gameLoop( event ) if(blocks ~= nil)then for i = 1, blocks.numChildren do blocks[i].x = blocks[i].x - speed if(blocks[i].x \< -0) then print("+1!!") obstacles = obstacles +1 end end end end Runtime:addEventListener("enterFrame", gameLoop) timerSrc = timer.performWithDelay(1000, createBlock, 0)