Side scrolling is not smooth - losing frames when set up 60fps

First of all I would like to say hello to everyone as this is my first post.

I am newbie in Corona and I am just staring my first projects.
I have been reading this forum for some time now and I have to say that Corona community is amazing :wink:
and I hope that you can explain me this issue.

I have noticed that side scrolling apps in Corona Simulator and in Xcode IOS Simulator do not scroll smoothly when fps = 60 in config.lua; It looks like the scrolling stops for a short while 1 - 2 times a second.

I used FPS widget from http://developer.anscamobile.com/code/output-fps-and-texture-memory-usage-your-app

I changed local maxSavedFps = 30; to local maxSavedFps = 60;
and it I noticed that min. FPS goes down from about 59 to 30 and then goes back to 58-59.

I tested it on:

  • Corona Simulator
  • XCode IOS Simulator

Tested it with Corona Sample Code - Horse Animation (you can see that scrolling stops when you look at the trees in foreground) and also with my small scrolling app (see code below)

I am not sure how it works on any device but I assume that the scrolling should be smooth in simulator?

Any advice?

Many thanks in advance.

– Simple Side Scroller –
save any nice picture that you can use as bg01.png (dimensions 480 x 320) and do not forget to change maxSavedFps to 60 in fps.lua

[code]
display.setStatusBar(display.HiddenStatusBar)

local fps = require(ā€œfpsā€)

local background1 = display.newImage(ā€œbg01.pngā€);
background1:setReferencePoint(display.TopLeftReferencePoint)
background1.x = 0
background1.y = 0

local background2 = display.newImage(ā€œbg01.pngā€)
background2:setReferencePoint(display.TopLeftReferencePoint)
background2.x = 480
background2.y = 0

local performance = fps.PerformanceOutput.new();
performance.group.x, performance.group.y = display.contentWidth/2, 0;
performance.group.alpha = 0.6; – So it doesn’t get in the way of the rest of the scene

– A per-frame event to move the elements
local tPrevious = system.getTimer()
local function moveBackground(event)
local tDelta = event.time - tPrevious

tPrevious = event.time
local xOffset = ( 0.4 * tDelta )

background1.x = background1.x - xOffset
background2.x = background2.x - xOffset

if (background1.x + background1.contentWidth) < 0 then
background1:translate( 480 * 2, 0)
end
if (background2.x + background2.contentWidth) < 0 then
background2:translate( 480 * 2, 0)
end

end

Runtime:addEventListener(ā€œenterFrameā€,moveBackground)
[/code] [import]uid: 51816 topic_id: 20891 reply_id: 320891[/import]

Hi Patryk - and welcome!

Is there a reason you need to use 60FPS? Could you give it a go at 30?

Peach :slight_smile: [import]uid: 52491 topic_id: 20891 reply_id: 82424[/import]

@peach: fluid user experience :slight_smile: it’s always better at 60fps!

as for the problem of frame skippinmg: have you tried it on a device? The simulators are just to help you develop, always test the issue on device. [import]uid: 44010 topic_id: 20891 reply_id: 82443[/import]

@Peach
Thanks for your reply
The thing is that it is not smooth at 30fps either. You can notice that especially when you use my example with just one picture in background ( Horse Animation has too many sprites that can disturb you). In Corona simulator it looks like the background jumps a few more pixels every 1 - 2 seconds. In Xcode IOS Simulator jumps are even more frequent,

I used example with 60fps in my previous post as it shows clearly that frame rate drops (min FPS drops to 30 as I mentioned) - when you set up config to 30fps - you just cannot notice that dramatic fps lose.

Ok - so I looked deeper in the code when I was writing this post and conducted some tests.
I printed the tDelta value which shows how much time moveBackground function had taken.

tDelta values (60fps)

16.146000000001
15.77
16.498
15.884
31.789000000001
16.214
15.557999999999
16.092000000001
16.119000000001
16.894999999999
32.095000000001

tDelta values (30fps)
33.018
33.007
32.868
33.094
32.986
33.138000000001
32.911999999999
32.883000000001
32.987999999999
33.029
33.474999999999
33.407
So it is quite easy to notice that at 60fps, the moveBackground function takes twice much time every few executions.

It is not so clear for 30fps, however I have noticed that ā€˜jumps’ occur when tDelta value is not rounded to 3 decimal places

I printed event.time values and all of them seem to be rounded to 3 decimal places so it looks like

local tDelta = event.time - tPrevious doesn’t work properly?

Any advice?

@r.pudlowski
I am still on the trial version and I understand that simulators are to help me develop :wink: As I wrote, I am just starting with Corona and that is also a process of learning about simulator possibilities. On other hand I guess that tDelta values I mentioned above will be the same on a device. [import]uid: 51816 topic_id: 20891 reply_id: 82451[/import]

you can export to device even if you are on trial :wink: [import]uid: 44010 topic_id: 20891 reply_id: 82452[/import]

@ r.pudlowski - ah yes, sorry :wink: My mistake! I meant that I do not have Apple Dev account yet as I want to buy it when I incorporate my Ltd company :wink: Some people reported problems with changing individual account to the company ones. I will read more apple forums and maybe I will do it quicker :wink: Thanks. [import]uid: 51816 topic_id: 20891 reply_id: 82453[/import]

@r.pudlowski
Since my last post I have bought Apple Dev Program, created profiles etc. and I run my little code on iPhone 4S.
so I can answer your question ā€˜have you tried it on a device?’ - yes I have and it looked fine on the device - min FPS was about 56, no ā€˜jumping’ in scrolling etc.

@peach pellen
Answering your question I would prefer to have 60fps as it looks much better especially with fast paced scrolling games. I tested my code at 30fps and 60fps on the device and there was quite big difference.

Do you recommend staying with 30fps? If so, could you explain me quickly any pros or cons from your point of view?

One more thing - tDelta values did not rise to 30 when I run the code on the device - they were about 16 all the time. However I got still some values with 99999999 or 000001 after 3 decimal places. Just like in my previous post. The same was when I run app at 30fps.

Not sure if this is important to you guys at Ansca but for me it is quite strange when you consider that it should be simple math subtraction. It seems it does not work properly and I think this causes problems on the simulator and I guess that when you have quite big application with similar code in many places it can affect the performance.
Let me know if I am wrong please :wink: [import]uid: 51816 topic_id: 20891 reply_id: 82512[/import]

i would go with 60fps, even if on the device it runs only 40fps, it’s still smoother than 30 :slight_smile:
30 fps can be better if you want to optimise the batery life, i think (the cpu/gpu is less stressed) [import]uid: 44010 topic_id: 20891 reply_id: 82547[/import]

This is a tricky problem; out of interest do you have an older device you might also test at 60FPS? I’m wondering if this is a simulator problem. [import]uid: 52491 topic_id: 20891 reply_id: 82648[/import]

Use Translate instead, its faster than the way your doing it and also smoother

[code]
Ā  Ā 

background1:translate(xOffset, 0)

–etc [import]uid: 84637 topic_id: 20891 reply_id: 82693[/import]

@peach

I run my code at 60fps on iPhone 3G

  • min FPS was usually in range 51 to 56
  • sometimes min FPS dropped to 30 or even 19 and scrolling was ā€˜jumping’ few pixels - it happened randomly - one time it happened 3 times in 5 sec, other time nothing happened for 20 seconds ( I assume that iPhone was doing something in the background which could slow it down, but this is a simple code with one scrolling picture and I hoped it would scroll at constant pace especially when there was no interaction from my side)
  • when I was touching the screen min FPS dropped to about 30 (by fast finger movement I could reach even 12 - 15 min FPS)
  • tDelta values were about 16 increasing sometimes to 90 when swiping finger rapidly
  • tDelta values had those x.xxx000000001 and x.xxx999999999 digits at the end (as in my previous posts)

Hope this will help you.

@Danny
Thanks for the hint.
I used Translate as you suggested but it did not help at all. It looked exactly the same on the simulator and iPhone as previously.
It was even worse when I used [lua] print (tDelta) [/lua] to print tDelta values. Min FPS dropped to 20 and sometimes it reached 30.
[import]uid: 51816 topic_id: 20891 reply_id: 82717[/import]

Print statements every frame cost a lot of fps.

Could you post up some more code? I think the slowdown is elsewhere [import]uid: 84637 topic_id: 20891 reply_id: 82720[/import]

@Danny

The code from my first post - that is all. There is nothing more. I have been using it for our tests.

When I want to print tDelta I put it in function
[lua]local function moveBackground(event)
local tDelta = event.time - tPrevious
print (tDelta)
… [/lua]
Printing tDelta in my original code works fine - code seems to run at the same speed with or without printing tDelta. It only slows down dramatically when I use ā€˜translate’ for scrolling as you suggested.

EDIT:
Of course it is not about tDelta - I do not need to print it. The issue I have been talking about from my first post occurs when I DO NOT print tDelta. [import]uid: 51816 topic_id: 20891 reply_id: 82723[/import]

Ok. and your images are 480x320 right?

if so il come up with a solution (after testing) and report back [import]uid: 84637 topic_id: 20891 reply_id: 82724[/import]

Yes, they are.
I tested the code with .png - size 209KB, and also with .jpg size 47KB - and got the same results.

Do not forget to change maxSavedFps to 60 in fps.lua ( and just to let you know fps.lua is not the issue here, I implemented it AFTER I had noticed that the side scrolling is not smooth)

And thanks for looking at this [import]uid: 51816 topic_id: 20891 reply_id: 82728[/import]

Ok tested this.

(On iphone 4s) it ran fine, min fps 57. however on simulator it was very choppy.

I will pass this onto the team [import]uid: 84637 topic_id: 20891 reply_id: 82754[/import]

Any news from the team? [import]uid: 51816 topic_id: 20891 reply_id: 87485[/import]