I'm developing a game for the iPhone. I've decided that 30FPS is plenty so I've written some code that only allows the App to present the render buffer every 1/30 of a second. When I tried to verify this with Instruments I got varying information.
On an iPod Touch (2009 edition, 32G) it reports 30 FPS for Core Animation Frames Per Second.
On an iPhone 3G I get wildly varying results. And not just less than 30 FPS. I see >30 FPS on a regular basis. It actually seems to hang closer to 36-39.
To investigate this anomaly I added my own FPS to the app and update it once per second. I stays right at 29 FPS on both devices.
So, does anyone have any suggestions as to what might be going on? I expect Instruments to be accurate so it really concerns me that it appears inaccurate. It makes me think I have a bug somewhere, but I sure can't find it.
Are you using CADisplayLink? This might give you a little bit more precision on your main loop.
Related
I'm building a SpriteKit game and have had a minor lag that I can't get to fully go away. CPU usage tends to vary, however, I see this lag regardless of whether CPU usage is >40% or <20%.
I've combed through the code to try to make it as efficient as possible (e.g., reusing nodes, hardcoding values, optimizing conditionals, etc.) and I'm about out of ideas.
I've noticed this difference between the FPS per the debug tool (120 FPS) and what I see within the SKView (~60 FPS, but never lower than about 58 FPS). My thought was that maybe the view controller running at a higher FPS is somehow stealing resources from the SKScene. I've messed around with preferredFrameRate, trying to set it to 120 in the SKScene (I don't think I can set it on the view controller) but that didn't change the rate on SKScene.
I'm using an iPhone 6s, so not exactly the newest iPhone, but I also downloaded another ball bounce game, One More Brick, and there's basically no lag whatsoever, so I don't think it's my phone.
Anyone familiar with this issue?
How do I take for example 25 photos in one second at low resolution?
I want to make a burst mode but with a lot of images at low resolution (640x480)
Later I need to increase to 40fps. I mean, take 40 photos in one second
25 frames per second is very close to the iPhone movie fps of 24.0 − 30 fps. Why not make a movie, then pull out the frames from the movie to get your shots.
The existing camera access in iOS spits out frames at about 30fps. You can't increase that, period. (I assume that this is due to the underlying hardware, but I don't really know.)
You'll also have a hard time with memory. 640x480 * 3 (RGB) * 25 frames ~= 23mb of RAM. Getting that much memory -- much less that much in a second -- in iOS is going to be challenging.
To get started with this, take a look around for AVFoundation sample code -- there's plenty of it to be had -- and experiment a bit to see what you can realistically and reliably get out of a device.
I tested my app with instruments:
When scrolling table views, it's around 20-50 fps, (more like 25 average). Is that good enough? I've reused the table view cells and did quite a lot of optimisations.
Slow frame rates are like pornography - hard to define but you know it when you see it.
In other words, worry about the feel, not the numbers. If it feels laggy, it is.
20-50 is great. Television has a frame rate around 30, and movies sometimes have frame rates as low as 24. For non gaming situations you can do just fine going as low as 15. Rates lower than that will start to feel laggy.
I made a board game with includes just some little animations. I reduced the fps from 60 to 30 to reduce the processor load. But the device still gets very warm.
Another application made without cocos2d is not heating it so much.
Are there any methods to calm the iPhone down?
The device state is as follows:
Wifi is always enabled
The app uses gamecenter
GPS is inactive
fps is always on 30
I use cocos2d-iphone as engine
It might be worth experimenting with different director types, e.g. kCCDirectorTypeNSTimer, and seeing if that helps at all. Those will have the biggest effect on the main loop of the game.
You should also spend some time with Instruments if you've not already, as that will show you where the CPU is spending its time and give you some hints on where you could ease things up.
I've noticed that a sequence of small time animations in cocos2d takes a lot of processor time. I've tried making tips at the level which will pulse in size. 0.1 second pulse up, 0.15 down and 0.2 stay. And i've put it all in a repeat forever sequence. Everything was terribly slow. Then i've just made the animation manually and the device calmed down and fps increased back to 60
When showing menus or dialogs that do not require animation, you can actually lower your framerate even further.
I've just come off the PSP where performance testing was easy. You just turned off 'vsync' and printed out the frameratem, then change something and see whether the frame rate goes up or down...
Is there any way to do the same thing on the iPhone? How do you turn vsync off? The Instruments tool is next to useless. Its chief problem being that it running it adversely affects the performance of the app! Also, the frame rate it reports is extremely sporadic.
I don't want any fancy tool that reports call trees and time spent in each function. I just want an unrestricted frame rate and some way to see what it is. Is there a high precision counter that you can use on the iPhone? Something like QueryPerformanceCounter in windows?
Also, is there anyway for you to somehow KILL backround processes so you know they can't effect the performance, perhaps solving the sporatic frame rate problem?
Profile your app with Instruments and use the Core Animation instrument. It gives a frame rate.
You're taking the try-something-and-measure approach. Very indirect. It's easy to tell exactly what is taking the time; it doesn't depend on what else is going on and doesn't require learning a new tool. All you need is a debugger that you can interrupt.
You can't kill background processes on the iPhone. That would make it possible for a buggy or malicious app to interfere with the phone function and the needs of all other functions on the iPhone are subordinated to the phone.
Try QuartzDebug or OpenGL Profiler.
Use instruments to get the frame rate.
To do this, run profile on your app (click and hold on the run button in xcode and choose profile). Make sure you are running your app on device. Choose openGL ES analysis. Look at the data display under core animation frames per second.
You want to aim for 60fps.