Hey guys,
Having a few problems with a couple of functions that I wrote that should simulate a bit of turbulence/mild shaking on an object periodically. Basically, every second it will apply a linear impulse to the object. The problem that I am having is that after about 10 seconds the game will literally grind to a halt! Severe drop in frame-rate. The object in question also has some Particle Candy FX attached to it, however, removing these effects only delays halting of the game by a further 10 seconds or so.
I’ve also tried literally shifting the object’s x/y coords by a randomised small number and had this on a repeating timer too. Unfortunately though, I need to also be able to control the object via touch and so altering the position of the object manually just makes the object then become impossible to control. I also tried removing the random number generation and just using a static value.
I’ve attached the code below. Can you please help to shed some light on what the issue might be? and, even better, suggest an alternative way to do this. I’m hoping it’s just something silly that I have overlooked…
Cheers,
Rich
[lua]
local initTurbulence – forward declaration
local function turbulence(xForce, yForce)
self.Player.turbulence = timer.performWithDelay(
1000, function()
self.Player:applyLinearImpulse( xForce, yForce, self.Player.x, self.Player.y);
initTurbulence();
end, 0)
end
function initTurbulence()
local randXForce = mRandom(-2,2)
local randYForce = mRandom(-2,2)
turbulence(randXForce*0.001, randYForce*0.001) – tiny force
end
initTurbulence() – invoked inside willEnterScene
[/lua]