MOzeb
MOzeb

Reputation: 423

Spritekit FPS drops when presenting UIView

I am finishing one of my project, a game made with Spritekit. I created a small menu with UIKit (1 view and few buttons). I connected SKScene and View Controller class to communicate so when game is finished, I am able to present menu.

I noticed problems with SKScene FPS. I already found some informations from 2015, on apple developer forum that this problem was spotted with iOS 9 for the first time. When I'm presenting UIView over SKScene, my FPS falls from 60 to 40. And after I hide UIView and run game again, FPS increases back.. But in about 2-3 seconds, what gives me a lag in my animations on start of the game. I tried with preloding all texture atlases first and nothing changed. Than I tought my textures are too big and problem is in my animations, and I decreased all images and its quality from 32bit colors to 16... But problem was not solved.

Then I also noticed that FPS is worse, if I animate UIView.. So there is definetly problem with combining SpriteKit and UIKit. I could pause scene before presenting UIView and unpause second or two after my view disappear again, and yeah maybe users wouldn't notice problem..

But what if I want to run my Scene in background of my UIView (like endless scrolling backgrouns), so background would move constantly when user enter menu? I know, I could do the menu with SpriteKit, but this approach seemed to work fine 2 years ago when I was last time using SpriteKit.

Upvotes: 2

Views: 453

Answers (1)

MOzeb
MOzeb

Reputation: 423

Okay.. I am posting an answer, if somebody else is searching a solution for similar FPS problems.

After your comments and recommendations what to do, I tried few different things and figured out some problems.

I tested it on two physical devices iPhone 6S and iPad 2. Of course results on iPad 2 are a bit worse.

UIKit and SpriteKit are surely not working best together. I figured out that there are no big problems with just presenting other UIViews or UIButtons over SpriteKit scene - FPS drops a bit but not really much, that this would make some big impact on your scene (2-3 FPS).

Biggest problems came in if you're trying to animate Views with some basic animations. In that case FPS (in time that animation is happening) drops to 40 - 35 FPS, and the biggest problem with this is, that sometime it just wont raise again until you make another animation or run scene again. I still don't know why this is happening, but it happens randomly. Sometimes FPS raises and sometimes not.

Another thing that also have big impact on SpriteKit frame rate are Ads if you're using them.

I am using AdMobs and in their documentation it's well written, that Banners or Interstitial Ads can make impact on your frame rate. I am not presenting Ads during gameplay, but also if you're presenting them in menu, this will decrease your FPS and when you run your game and your FPS drops again for a bit, the result will be even worse. So I suggest you run your Scene with delay or hide banner a bit earlier so it won't have impact on your start of the game.

I found solution for my problem with pausing the scene as soon as gameplay ends, so when menu appear my Scene is on pause mode. And after I run my game again I am un-pausing my Scene. It's not the best solution for my case, but it works much better now.

I suggest to use SpriteKit also for your menu creation, this way you won't have such problems. Or even better - use some other game engine for your game creation.

Upvotes: 2

Related Questions