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.
Related
I'm learning Unity right now, and I want to animate a sprite of Mario running.
I found a spritesheet and have cut out 3 images.
I select my Mario game object and create a new animation
In the animation window, I put in 3 spites at the times I want to animation the run
When I press play, Mario is running, however he is also shifting position a little bit in the X direction but then resetting as the animation loops.
Why would my Mario object be shifting a little bit as part of the animation cycle? Where would I look to see an attached property or behavior that is causing him to do this? Maybe I moved the object while I had record on? I deleted all the associated animation objects and recreated them but Mario is still moving.
I figured it out. I had a pivot point created on a single frame of the sprites. This would screw it up.
I'm trying to play sprite animation in unity, it is playing but when ut is playing the animation is flickering
How to solve this issue
I had a sprite animation on layer 0 placed on top of a background sprite image and got the flickering as well.
Change the sprite "order in layer" property to 1 (and leave your background sprite set to "order in layer" zero.
Flashing went away.
I had same problem. I fixed mine by adjusting the sorting layer. The flickering is caused by overlapping sprite.
So, your post came up in the searches. I was having a similar issue. For me, the animation would play, but there was a couple of bad frames/sprites that would be there as far as 'in' the animation, but they just weren't showing on screen. I could click on the frame image and it would show, but during animation it would disappear, causing the flashes.
But, by having the pop-out animation window open that can play frame by frame, I could figure out where the flash was. (Again, everything appears correct. Double-checked that it was set up the same as all others.) If you also watch the inspector window with the object selected, you can see the name of each animation frame as it goes by. So I did the frame-by-frame and saw that in two spots it said 'Sprite Missing'.
I figured they were just corrupted so I deleted them. But, the problem was still there (indicating that it wasn't an image issue.) Surprisingly though, when I tried dragging just those two images back in, everything worked fine. Who knows why 🤷♂️
Anyway, mine at least was a simple fixed once I kind of figured out where the issue was at. so, hopefully this might help someone else out at some point.
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.
How can I show 2 scenes on the screen at the same time on Sprite Kit Swift?
I need to first scene be placed of the second (I need one scene to be seen and atop of it appeared other scene, which has some sprites).
Or tell me, how developers make, for example, menu (with buttons like "restart", "results") to appear on other scene when player dies? And that time, also you can see the main scene with location (or with dead character)?
You do not need 2 scenes. However, you can accomplish what you are after with basing an node tree off of an SKNode. For your menu idea you could build it out of however many objects you'd like, but since it is based from an SKNode, you can animate it to your hearts content. No need for two scene, just build another node tree and animate the root. If that isn't enough answer, I could write some code to help you out if need be. Sorry watching the Netflix and feeling lazy.
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.