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.
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.
Related
I use Unity 2020.3.8f1. I've developed a scene with an FPS controller so it can be walked through. Yet, sometimes when I click play, the scene shows upside down and sometimes the camera is looking at the sky or off to the side. It doesn't happen always, just randomly at unpredictable moments and looking in different directions. Does anyone have any idea what is going on?
It happens only with this one file. I've created other scenes with FPS controllers to walk through that have always worked with no problem. With this error=prone walk through, there are no errors in the console and no error messages appear on screen. The scene was built with prefabs, so the only scripts are the ones that come with the FPS Controller.
Thank you,
Michelle Jensen
I've just started learning how to use sprite kit, I've almost completed my first game, however I have come across a problem which I don't really know how to solve, basically when I first load the game/scene the game is very laggy FPS drops to about 30, and movement and animations are not smooth, however soon as the first scene is finished and play again everything is super smooth? so initial load is slow, second and every load after that is fine, I need some pointing in the direction, thanks
I am having this weird problem with my game menu when I use SKShapeNodes instead of SKSpriteNodes. The menu is basically a subclass of SKNode and just has different SkSpriteNodes as buttons, its pretty straight forward.
Recently I changed the SKSpriteNode buttons to SKShapeNodes because it gives me some extra benefits (rounded corners, strokes etc). However the problem now starts when the game menu is shown.
Basically if a press the "homeScreen/Main Menu" button in my game menu a scene transition happens to another SKScene. The issue is that when the scene transition finished I can briefly still see the SKShapeNode buttons for like 1-2 seconds and than they disappear. Sometimes its just the buttons, sometimes it is the menu also. It sort of looks like LCD screen burn.
Whats even weirder is that if I only use 1 SKShapeNode button and the others are SKSpriteNodes the effects is the same, all buttons briefly show after the scene transition.
Using only SkSpriteNodes and this does not happen. Changing the scene transition style seems to make no difference too.
Has anyone had the same problem or maybe know what could cause this?
Thanks for any help or support.
So after more reasearch it turns out that SKShapeNodes are notorious for memory leaks and performance issue. In my case I was simply using to many SKShapeNodes. Solution is to either reduce SKShapeNodes count or using alternatives such as SKSpritenode.
I am trying to make a loading animation while using LoadLevelAsync to load the next scene.
The loading animation is a loading circle that continuously rotates in the middle of the screen, and I use LoadLevelAsync("NextScene") in the code. The problem is that every time right before the scene switch happens the circle will freeze for a few milliseconds before the next scene appears.
I do know that the less things the next scene contains, the shorter the freeze is, but I thought that LoadLevelAsync's purpose was for letting the user experience no lag during scene transitions. My next scene contains a background sprite, some buttons, scripts, and a 3MB audio file. The screen will always freeze for half a second before showing the next scene.
I am using Unity 4.6.3 with Pro feature. I'm also testing the results on a device. I have also tried out the AsyncOperation.allowSceneActivation with Coroutines, and unfortunately they don't work.
If anyone has a solution, or has any suggestions on smooth scene transitions, I would greatly appreciate them.
Thanks in advance.
How do I do this?
On one of my UIViews (nib file) I have ImageView and a Button that starts full screen Cocos2d scene. From within that scene I want to close it and go back to UIView, so that user can later open the scene again but from different image in ImageView (and with different content on scene).
However, after the first time I "close" the scene the whole app reacts a lot slower to all touch events. It works fast as long as the scene is on, but when closed then performance goes down.
How should I properly close the scene so that I can restart it again? I've browsed through a lot of code samples and everywhere is just replaceWithScene:newScene.
Adding a UIView to a viewController that houses a running openGL layer slows the app, as anyone who has tried to incorporate a UIScrollView into a Cocos2D game can tell you. You are closing the scene, but likely not stopping the CCDirector, which is now running its own scheduler aside the application's scheduler. As they fight for dominance over the CPU, OpenGL invariably wins as it needs more power more often.
Ensure you are completely shutting down cocos2D and OpenGL. Even if only calling [[CCDirector sharedDirector] pause].