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

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.

Related

SpriteKit animation stops unexpectedly

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

Architecture of a SceneKit game, multiple view controllers for menu screens?

I'm working on a SceneKit game using Swift, and I'm thinking about the best way to organize the various screens/ states surrounding the actual main game scene. I have a simple prototype which consists of three states:
Splash Screen (choose game type) ->
Game ->
Game over screen (choose to play again or return to splash)
In the prototype I opted to go for UIKit to do the UI elements, rather than a SpriteKit overlay. Although it's just buttons at the moment, which would be easy enough to do in SpriteKit, I might in future want to add sliders (eg an options screen to set control sensitivity etc), text entry etc, and then you end up recreating great chunks of uikit.
So at present, each of the 3 scenes described above has its own UIViewController. The Splash and Game ViewControllers have their own SCNViews and SCNScenes, and the GameOver is a modal that displays over the main Game scene.
This structure isn't really ideal, as it means that the main game SCNScene gets reloaded whenever the viewDidLoad of the GameViewController fires. The main SCNScene is quite detailed so takes a few seconds to load, and with repeated cycles this seems to create memory issues. After 2 cycles of Splash -> Game -> GameOver I get a memory warning, and after the third cycle Xcode loses the connection to the iPhone (which seems, in my experience, to be caused by memory issues).
I would like to have a main GameViewController that loads the most frequently reused assets once, but still be able to segue between the various menu screens.
So what are the options here?
I thought perhaps I could have a main GameViewController which controls the loading and unloading of SceneKit assets and has the sole SCNView. Its viewDidLoad method would only be fired once, when the app first starts. Then, each of the other views would have a very minimal UIViewController, which would be presented as modals over the main GameViewController, with "OverCurrentContext" selected.
I wanted to ask whether this pattern sounds feasible, and how others organise their SceneKit games. I'm still quite new to native iOS development, so it could be that I'm missing some basic game design pattern.
My Experience with the use of only one GameViewController (my current work for MAC OS X: i started a a 'small' 3D game with a MainMenu/start screen, a Hud and 2 or 3 complete different 3D Scenes - this shall be ported then to IOS, too):
In the last week i tried what you asked for, to use only one GameViewController for "all" that stuff - for me it seemed to be the easy and "good" way to do it - but even after lot of hours with all my tricks I've learned the last years i was not able to reload load another (or change) 3D scene (or even not another sprite kit scene hud) after a scenekit scene is loaded in a single ViewController.
Maybe there is difference between MAC OS X and IOS but i even tried this in an iOS version and it has the same behavior.
What i was able to do: You can modify a loaded 3D scene or change data in the sprite kit hud etc., so you are able to use one 3d scene to add or show the things up when they are needed but as far as my tests here showed, you will need one ViewController to show up a complete new different 3d scene or 2d/3d Menus etc. I will post my further experiences as soon as I'm a step further. i hope this helps a little.

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.

Animation in Launch Screen in xcode 6

I want to animate a set of images in my Launch Screen, but I do not know how. I have seen some tutorials telling me to put code in the App Delegate (DidFinishLaunchingWithOptions) and nothing has worked.
Could someone help me animate my Launch Screen?
I am supposing that you do quite a bit of work on launch, and you do not want your user to stare at a static image while this work is going on. What you need to do is do the work in the background (using gcd). This way, the launch screen will be gone quickly. However, you are not ready of course: hence your need for animations. So what I do is add my own equivalent of the start screen on top of my first visible UIView, do my animations and then tear down my start up screen. If you want to see what I do in action, try it out with my App (The Opera Player)

cocos2dx animations lag whenever admob receives ad

I'm running smooth CCScaleTo actions in my cocos2dx(v2.0.4) game scene. After adding admob(v6.2.1) to cocos2dx's openGLView, the actions lag whenever admob receives a new ad.
I test two cases:
Remove the ad view from view hierarchy. The animations lag when admob loadRequst:
Comment out the admob loadRequest: and add the ad view back to view hierarchy. The animations lag within the first few seconds game scene load.
It seems related to UIKit & cocos2dx integration issue.
Any idea to workaround?
The trick that comes to mind is: don't let AdMob handle its own display (since it will insist on doing that animation). Instead, build the Adview, and only add it to your view hierarchy AFTER the normal animation would have finished, using i.e. dispatch_after.
Ideally you'd wrap the UIView in a cocos2d object so that CCDirector can do the animations instead of UIKit. That might be more work than it's worth, but it would definitely keep the animation thread from blocking.

Resources