10
votes

I'm writing an iOS game, using SpriteKit. At, apparently random, times during gameplay, the frame-rate will drop from 60 FPS to 40 FPS (always 40). I'm running this on an iPhone 6. The bug is present when building for release and debug.

I typically have around 30 nodes on screen at a time (sometimes less), most of those nodes have physics bodies, however, all but around 5 have dynamic set to NO. The aforementioned physics bodies do not collide with each other, however they do collide with the player node. The player node is not moving quickly, and usually is only touching around 5 or so nodes at a time. When the player node comes into contact with some of the other physics bodies, their dynamic property is set to YES. It might also be worth mentioning, that I have a couple of UIViews and UIImageViews overlaying the top of the SKView, acting as the HUD.

It strikes me that this is not a particularly intensive simulation. I have gone through my - update: methods, actions, contact listeners, etc. and not found anything that might be causing this. I've spent the last few days in Instruments (Time Profiler), hoping it might shed some light on the matter, but again, I've not found anything that jumps out at me. However, I'll admit to being quite new to Instruments.

Right now, I have no way of reproducing the bug. I just have to play the game, and hope to encounter it. Sometimes it will happen when the scene loads in (quite rare), just during normal gameplay, or not at all. If I pause the game (pause the view and scene), and resume it, the frame-rate goes back up. Sometimes the frame-rate will return to normal after several seconds. I'm completely at a loss of what to do here. Any help would be much appreciated.

Thanks in advance.

1
Have you tried rebooting the phone, and running the app in release without the debugger connected? (unplug the cable) And try it without the UIView components for testing, as they might interfere, especially if you have a couple of them. - LearnCocos2D
Removing the UIKit items just as a test certainly doesn't hurt. The other thing you can do, just for "verification" is add some code to measure the intervals between updates. See how consistent they are. - Mobile Ben
@MobileBen Hi Ben, just removed all UIKit items (including UIButtons). Don't want to speak too soon, but this appears to have fixed the problem. Will do some more testing (can't quite believe it :) ) and report back. Re. your second comment. I'm not using any textures. Could you explain what you mean by "generalised draw order?" - baxterma
If you are finding UIKit is problematic, then I would recommend seeing if you could find SpriteKit "equivalents". So for example, all my buttons are actually SpriteKit buttons that roughly act like UIKit buttons. - Mobile Ben
The problem with UIViews is that they aren't "realtime friendly", some less so (UIScrollView) than others. For instance scrolling in a scroll view is known to freeze or drop fps of OpenGL views, or the other way round where the scroll view is "jumpy" due to OpenGL view using too much resources and CPU time (on the same thread). Depends on how the game loop is implemented. It may also make a difference if the UIViews are children of the SKView, or whether they are siblings (ie both having the UIWindow as parent view). - LearnCocos2D

1 Answers

0
votes

The only thing I can think of for why you would have a massive frame rate drop is if all the textures for your HUD is not already pre-rendered. So you might have the initial HUD pre-rendered and some other images but some images the HUD uses when some event is triggered in game.