Hi!
I’m programming a game in which I want to evaluate some condition (the velocity of a ball) every frame, just to make sure it has stopped. When it stops, it must change the scene.
I can’t make it to stop the listener, unless I do it in the unload function. But then it’s too late. Can I remove a listener from the same function?
It’s 7 o’clock, and my brain can explain himself better than this. I’m posting my code so you all understand what I mean:
local gameLoop = function()
local vx
local vy
vx, vy = pilota:getLinearVelocity()
if (math.abs(vx) \< 20) and (math.abs(vy) \< 20) then
pilota:setLinearVelocity(0, 0)
Runtime:removeEventListener("enterframe", gameLoop)
\_G.posX = pilota.x
\_G.posY = pilota.y
if (contadorGolpes == #arrayColores) then
gameOver("yes")
else
print("Fracàs!")
gameOver("no")
end
end
end
Is this ok? Because this listener won’t stop listening.
Thanks in advance!
Hector [import]uid: 36639 topic_id: 9683 reply_id: 309683[/import]