SpriteKit, Seemingly at Random, Drops To 40 FPS

2019-02-12 18:44发布

问题:

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:

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.