I have an external module that creates an object and then is called to oscillate the object along the y-axis while the game is running, and stop when paused. The object making and “start” call for oscillation works fine, but the Runtime:removeEventListener(“enterFrame”, oscillate) isn’t making the oscillation stop. If I have a scoping issue, I’m not seeing it. Thanks.
- Obj.lua
local M = {}
function M:new()
local object = display.newImage(“image.png”)
… other code for placement
function object:oscillateStartStop(action)
local self = self
local function oscillate(action)
if (ifStop == true) then Runtime:removeEventListener(“enterFrame”, oscillate) end
local getTime = system.getTimer()
self.y = ( self.y ) + ( math.sin( getTime * 0.0015 ) * 0.5 )
end
if action == “start” then
Runtime:addEventListener(“enterFrame”, oscillate)
elseif action == “stop”
oscillate(true)
end
end
return object
end
return M
–main.lua
local thing = M:new()
thing:oscillateStartStop(“start”)
…pause the game later on
thing:oscillateStartStop(“stop”)
– oscillation doesn’t stop though print functions state that functions are being called