SpriteKit animation stops unexpectedly - ios

I'm trying to debug a very strange behaviour of SpriteKit animation. It's quite easy to reproduce:
Create a new Game project in Xcode leaving all the options unchanged.
Open GameScene.swift and change line #23 from label.run(SKAction.fadeIn(withDuration: 2.0)) to label.run(SKAction.fadeIn(withDuration: 0.2))
Connect your phone and start a debugging session, observe how the text (Hello, World!) fades in and appears in full brightness. Well, so far, so good.
Stop the application from Xcode and start it again clicking its icon on your phone.
Observe how the text, although visible, is not faded in completely.
I found this trying to understand why my animation just stops half the way when my application loads. I assume that somehow the view stops refreshing if some initialisation step is longer than the animation but I don't know how to fix this. I also noticed that if you click on the screen it refreshes and the animated view appears in the final state.
iOS version: 10.3

I've discovered a serious issue with iOS11 and SpriteKit. The Game Scene during the transition is getting paused automatically (but only in iOS11).
After transitioning to the scene run
myScene.isPaused = false
and it should fix the issue, and should have no adverse affects when the game is run on iOS10

Related

SpriteKit 40.0 FPS/Performance issue

I have created a spriteKit game and have a problem with performance issues.
Problem:
FPS gets stuck at 40.0
How and when does it happen
1. I have a pause function in my game by just using view!.scene?.paused = true Sometimes when I hit the home button, launch another app, then go back to the game the FPS gets 'stuck' at 40 and doesnt climb back up to 60.0. (Sometimes it does)
2. I have a 'sharing' Facebook and Twitter icon where when you tap on it you can post/share/tweet something on your account. This icon can be seen in the pause menu. After posting or returning back to the game FPS gets stuck at 40 FPS (And again, sometimes it does climb back up to 60. Sometimes it does not)
3. To clarify, this doesnt happen mid-game. This only happens if I minimize the app, launch the Facebook/Twitter icons, during reminder pop-ups.
Temporary fix
There is a temporary fix to this, which is to minimize the app and then launching it again. However, I wouldnt want my users to experience this at all. If possible Id like to eliminate this problem altogether.
What I have tried so far to fix this
1.Ive tried running this on instruments (time Profiler) but nothing really caught my eye. Thought I have to say I am quite new with instruments.
2. There is a similar question here but for him disabling UIKit items fixed it for him, and I dont have any of that.
3. I initially thought it was a SKShapeNode issue so I changed my sprites to SKSpriteNode. No help here either.
4. I have tried without the USB cable attached to the phone and tried running it using the Run button on XCode. No difference.
5. Ive tried rebooting device and laptop. Didnt help.
6. Tried this on multiple devices. Same issue.
Stats?
Game typically starts out at 20 nodes and 5 draws and can go up to 60 nodes 6 draws but it will actually still run smooth as long as I dont initiate any of the triggering methods mentioned above.
I have spent alot of time trying to find a solution for this. Changing codes and streamlining it. Googling it. I really need help on this one. I would really appreciate some help.
Update for comment #1
For you first inquiry
1) I have a SKSpriteNode as the pause button during gameplay for the user to pause the game if he wants to.
2) I have func applicationWillResignActive(application: UIApplication) {} in my AppDelegate.swift file that triggers a GameScene.swift function that changes a flag from true to false so that I know when the user goes out and come back in again. And I have my update block searching for that flag. If it is true, display the pause menu. However, this 40FPS issue happened before I added this whole pause/unpause thing. (The 40 FPS issue is what made me create the pause menu for this) (I know too in the latest ver. of swift that it will auto-pause when the app is minimized and unpause when I bring it back up.)

UIWebView HTML 5 game Canvas drawing slowness in iOS 9, or WebGL crashing in iOS 8.0 and above

I've having an issue with UIWebView and running HTML 5 games (that another developer is working on). We've tried two different options, and neither is optimal.
Option 1: He renders the HTML 5 game with "canvas drawing". When he does it this way, nothing crashes, however in iOS 9 when we go back into the app from the background, the Web View loads back up, but the game is moving much slower than normal (issue not on iOS 7.1 and above). By much slower I'm talking about the animations are not moving the same velocity that they were when we first load the game. The weird thing about this issue is that even if the user opens up a different HTML 5 game (we're adding multiple games) the animations are slower for that game as well. I've tried dismissing the Web View Controller when the UIApplicationWillResignActiveNotification gets posted. When I set the game up this way, the slowness only happens if the app is in the for 4 seconds (it's very strange).
Option 2: He renders the game with "WebGL". When he renders it this way, the app crashes when the app gets backgrounded on iOS 8.0 and above. My research into the crash is that iOS can't draw OpenGL ES in the background. I'm assuming that the WebGL commands are running similar commands as OpenGL ES would do, hence the crash. Dismissing the Web View Controller on UIApplicationWillResignActiveNotification still causes the crash to happen.
Has anyone else ever dealt with a situation like this?
I've not found a good solution to the problem, but I did find a work around.
When I get the App Will Resign Active message, I remove the UIWebView from the UIWebViewController's subview. When I get the Did Become Active message, I add the UIWebView to the UIWebViewController's subview.
This solution works for both cases.

Presenting a new viewController doesn't seem to unload the previous

The game I'm developing consists of a Main Menu, and Game viewController separately.
However when moving from the game screen to the menu screen, it seems as if the class files from the previous viewController are still in effect?
For example, players start the game by tapping anywhere on the screen whilst in the game viewController, which causes a new bar to be "launched", which in turn plays a small tone which varies depending on the direction. However when returning to the main menu after the game is over (achieved by pressing a button to present the menu viewController), tapping anywhere on the menu screen seems to start the game again from the game viewController?
By this, I mean the bar launch sound is played, despite there being no code available in the main menu viewController to play said sound, pressing play on the menu will take you to the game screen, where the game has been reset, until tapping again, where the sound plays implying a new bar is launched, despite all images being invisible.
I made sure that, when leaving any view, I wipe all subviews from the view, so that whenever the screen is loaded there's nothing being covered up. I also tried dismissing the previous view controller, however nothing seems to take effect. So, I can't tell for certain whether the views are being removed or what... It's simply mind breaking to me.
Unfortunately my descriptions most likely aren't doing myself any justice, so hopefully this video demonstration will help out. Note that at the beginning, I am tapping the screen to show that no sound is played, however of course that won't be visible.
Edit: You'll notice that when returning to the menu, tapping the screen seems to mess up the moving bar in the background, despite the gameBarMovement timer being invalidated upon moving from the game to the menu. The fact that they're using separate class files also should mean the bars shouldn't be effected? Knowing me, I've missed something fairly obvious.
This is how the UIViewController life-cycle works as far as I know. UIViewcontrollers aren't unloaded until the app starts running out of memory. What you probably need is some way, in your game VC, to stop the game loop from running and resume it once a new game is started.

iAds and SpriteKit: SKScene Freeze on fullscreen exit on device only

My issue is similar to this one here
iAd freezes game's scene, but I feel the issue hasn't been resolved.
I have an iAd in it's own view overlayed over an SKScene so that it doesn't affect the SKScene sizing. The banner functions correctly but on fullscreen exit the SKScene is frozen. App is still receiving touch inputs, verified via NSLogs. If I click the banner again though and exit fullscreen the second time around the SKScene is no longer frozen. Why?
It's important to say that this happens only when testing on a device (iPhone5). On the simulator, there are no issues. Has anyone figured out this conundrum?
Issue is similar to this post iAD View Freezes On Ad Close but the solution: 'Remove self.canDisplayBannerAds = YES' doesn't work for me.
While I've tried creating it programatically also, I've implemented the iAd via storyboard, and this is not relevant.
The issue is also here iAd Freezes App iPhone 5[s][c] but the solution is short of superstition and still remains a mystery.
--
The alternative solution to implement an iAd with SpriteKit via self.canDisplayBannerAds and originalContentView works and functions correctly but produces a sizing/scaling issue as it shares the view with the SKScene (Spritekit iAds messing with scene size) which I'd rather avoid, but am willing to use smoke and mirrors to hide the ugly resizing animation/effect as a last resort.
--
If anyone knows the best way to implement an iAd with SpriteKit without sizing issues or freezing issues on device please let me know.

iOS 7.1 animation bug

Yesterday I updated my iPhone 5 to iOS 7.1 and found a strange bug in my current application. There is few UINavigationControllers. After few transition in it the animation of transition become to fast, like there is no animation at all. But more strange that all system animation became to fast, default UITableCell animation, modal window animation and so on.
Does someone know what is this? On device with 7.0.6 there is no such problem.
Looks like it starts to happen after few calls of:
[navController setViewControllers:popViewControllers animated:animated];
PS: One more thing - my app is still using iOS 6.1 SDK.
PPS: i don't use custom default animations.
UPDATE: With 7.1 SDK problem still exists.
I have similar problem after updating my iPhone from iOS 7.0.3 to 7.1. I go back and forth several times using the navigation bar and after a few tries there is no transition animation. All animations are broken when it happens, eg. device rotation animation. After reaching this state, few more back and forth transitions cause a crash.
Edit 3:
In my case the problem was because of accessing GUI objects from a background queue. If you experience this issue make sure all GUI objects are accessed from the main thread. Many thanks to Eugene for helping me figure this out.

Resources