why is only 60 fps really smooth in cocos2d?
Asked Answered
T

2

9

It has probably been asked before, but I can't find it anywhere...

In videoland, 24 fps and anything above is smooth. Cocos2d seems to be smooth only when its 60 fps or maybe a bit less. Anything between 30 and 50 is certainly not smooth, the fps counter doesn't seem accurate...

Why is this? Or is it only me having this situation?

Toland answered 11/12, 2012 at 23:21 Comment(0)
A
25

There are actually several reasons for this behavior, and it's not just cocos2d but an effect seen in any game engine in environments with vertical synchronization (VSYNC) enabled. On iOS VSYNC is always on, on PCs you usually have the option to turn it off to improve framerates if they are consistently below the monitor's rate at the cost of screen tearing. Typically LCDs like iOS devices update their display at 60 Hz, allowing a maximum of 60 fps.

Cocos2D 1.x defaults to using the CADisplayLink class for updates, Cocos2D 2.x uses CADisplayLink exclusively. CADisplayLink causes updates to be synchronized with the screen refresh rate. Meaning a notification is sent when the screen has finished drawing its contents.

When you get 60 fps all is fine. But if the game can't manage to render a frame in time to render 60 fps, it will receive its next update only after the next screen refresh has completed. This effectively halves the framerate as soon as the framerate drops just below 60 fps - or in other words as soon as your update & render cycle takes longer than 16.666 milliseconds to complete. This means you can only have discrete framerates of 60, 30, 20 and 15 fps (60 divided by 1, 2, 3 and 4) on iOS with CADisplayLink updates.

The effect is quite noticeable because a framerate that fluctuates between 60, 30, 20 and 15 fps - even just for a fraction of a second - doesn't feel smooth mainly because it's so unsteady - the unsteadiness is what we notice as "not smooth". If your game is affected by this, you might find that limiting the framerate to 30 fps will actually make the game appear smoother. You also have more time to update & render stuff between frames.

It's the steadyness of the 24 fps movie framerate that is conceived as "smooth", but also movie directors have learned to avoid scenes where the limited framerate becomes all too obvious. For instance, they avoid as hell what games do very often: scroll sideways, ie sideways movements of the camera or sideways movement of objects passing by the camera.

You'll be surprised how much smoother movies can be when you watch The Hobbit - it's the first blockbuster movie to run at 48 fps. You'll immediately notice how much more "real" and "lifelike" the characters in the movie are. To get an impression, check out this unofficial 48 fps The Hobbit trailer.

What cocos2d displays as fps is not an accurate representation of the switch from 60 to 30 to 20 and 15 fps but the average framerate over several frames. Therefore when cocos2d prints "45 fps" it means half the time the game displayed 30 fps, the other half at 60 fps over the past couple frames.

Attainder answered 12/12, 2012 at 9:23 Comment(2)
as always, a treasure trove of useful info. thks.Brisket
oops, missed your answer for a moment :). very informative indeed, thank you !Toland
U
2

Two main problems.

First is matching the refresh rate of the display - anything else and you get irregular motion which the eye/brain is good at spotting. At least be at a multiple of it.

Second is motion-blur. Film/video tends to have motion blur, which fools the viewer into seeing continuous motion.

Unfurl answered 11/12, 2012 at 23:30 Comment(4)
I see, that makes sense. But desktop monitors also often have 60hz refresh rate. I can't remember noticing having trouble with desktop games that have lower fps then 50. Maybe I'm mistaken...Is it something typical for the iphone?Toland
Desktop monitors are usually a bit higher than that these days. Plus some cheaper LCD displays will blur a bit. Otherwise nothing particularly special going on.Unfurl
I have noticed flickering with 60Hz monitorsFabri
Desktop games at 50 fps will feel smoother if VSYNC is disabled. That "flickering" could have been screen tearing caused by VSYNC being disabled.Attainder

© 2022 - 2024 — McMap. All rights reserved.