Jerky / choppy / non-smooth image movement

Hey Community,

I have a problem that took me several hours without any solution.

Actually I am building a endless runner app with moving background (parallax effect) and moving platforms the player can jump to.

I update the background as well as the platforms on every frame. I started moving the objects with a constant “speed”-value. The result was a jerky image movement.

You can see this behaviour here:

https://www.dropbox.com/s/bn17r80047mh2sv/corona_scroll_test.mp4

After a bit testing I figured out, that the frame rate is not constant (something between 20 - 66 FPS), so 

I improved the movement by moving the objects frame-independent, as you can see in the code below.

Sadly this did not fix the problem. 

Funnily enough, it is also jerky when moving the objects very slowly…

After a long research I found a couple of people having the same issue, but it seems, that no one has a solution.

Thanks in advance to everyone replying to get a step closer to a solution.

Best regards

  Chris

local runtime = 0 local function onEveryFrame( event )    local temp = system.getTimer() dt = (temp - runtime) / (1000 / display.fps) runtime = temp   ...  for i = self.myobjects.numChildren, 1, -1 do     child = self.[myobjects]     -- Move object     child.x = child.x -(speed\*dt) ...

Are you removing objects during runtime and re-creating them? If so you will probably see temporary drops in the frame-rate when the garbage collector kicks in, especially in a game like this that has a fast paced nature.

The best solution is to create a pool of objects initially, then recycle them when needed.

For example, create 20 coins on startup, when one goes off screen hide it. When needed reposition it and set it to visible again.

Also test on device, the simulator can show choppy movement at times, whereas the device is nice and smooth. (Depending on your frame-rate of course)

Hope this helps.

Hello Gremlin Interactive,

thanks for your answer.

Meanwhile I reduced my project so that I only have one image object moving from right to left, after passing left screen, passing the same object to the right, and move it again from left to right, …

So I don’t think there is a Garbage Collector problem.

I also tested different devices, the most powerful of them a Nexus 5, I have got the issue on all devices, as well on the simulator.

Any other suggestions?

Hi @ all,

I’ve create a test project, with minimal code size, with this issue, non-smooth / jerky image movement.

Hope this helps that someone finds a solution on this.

Best regards,

   Chris

I’ll try and take a quick look at this for you tomorrow if i can. I can’t promise anything though i’m afraid. Swamped at the moment

No other suggestions? Corona staff?

There are many people out these with the same problem without any solution.

I hope someone can help me out of this essential problem.

Best regards

You could also try setting your config.lua fps key to 60.

Then try again on device.

Already done, same behaviour - on the devices as well.

Try moving the object without factoring in the delta time.

I have a side-scroller I am working on that scrolls multiple buildings, floors and objects and it does run jerky in the simulator but fine on devices.

If this doesn’t help then I would suggest sending off your test project to corona via the file a bug link at the top of the page.

Are you removing objects during runtime and re-creating them? If so you will probably see temporary drops in the frame-rate when the garbage collector kicks in, especially in a game like this that has a fast paced nature.

The best solution is to create a pool of objects initially, then recycle them when needed.

For example, create 20 coins on startup, when one goes off screen hide it. When needed reposition it and set it to visible again.

Also test on device, the simulator can show choppy movement at times, whereas the device is nice and smooth. (Depending on your frame-rate of course)

Hope this helps.

Hello Gremlin Interactive,

thanks for your answer.

Meanwhile I reduced my project so that I only have one image object moving from right to left, after passing left screen, passing the same object to the right, and move it again from left to right, …

So I don’t think there is a Garbage Collector problem.

I also tested different devices, the most powerful of them a Nexus 5, I have got the issue on all devices, as well on the simulator.

Any other suggestions?

Hi @ all,

I’ve create a test project, with minimal code size, with this issue, non-smooth / jerky image movement.

Hope this helps that someone finds a solution on this.

Best regards,

   Chris

I’ll try and take a quick look at this for you tomorrow if i can. I can’t promise anything though i’m afraid. Swamped at the moment

No other suggestions? Corona staff?

There are many people out these with the same problem without any solution.

I hope someone can help me out of this essential problem.

Best regards

You could also try setting your config.lua fps key to 60.

Then try again on device.

Already done, same behaviour - on the devices as well.

Try moving the object without factoring in the delta time.

I have a side-scroller I am working on that scrolls multiple buildings, floors and objects and it does run jerky in the simulator but fine on devices.

If this doesn’t help then I would suggest sending off your test project to corona via the file a bug link at the top of the page.

Even I am facing same problem.

Anybody got solution?

Wow. Does it run like this on the device as well? My project is, uhm, infinitely more complex and it runs supersmooth, even on an iPhone 3, so I’m sure there is a problem somewhere.

I’ll try checking your code, but I don’t have the time to delve in deeply, so no promises here.

Hi! Just checked your code. No major issues here, but I do see some red flags.

You are calling display.fps on every frame. Don’t! Just set this to 30 or 60, whichever you are using, but don’t make a system call every frame that is unnecessary.

local deltaTime = temp-runtime

imgObj.x = imgObj.x -deltaTime*speed

Should suffice. Try this and let me know how this goes.