cocos2dx animations lag whenever admob receives ad - ios

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.

Related

How to stop/handle UI Operations in iOS when app moves to background state?

My app can be launched via UIApplicationLaunchOptionsLocalNotificationKey in the background. In that case the usual flow to setup initail view controller and some animations on the app's landing-page/first-page of the app take place.
My question is, Is this a good practice, If I leave these animations like this even when my app is launched via OS in background? Three things I am concerned about:
Some animations are continuous, like a circular-dot(UIImage) expanding and shrinking, using CAAnimation.
Some views are added and removed as subviews to the keyWindow, based on user location.
When user taps the home button, do I need to stop the animations and subview additions then also?
Making the animation stop and resume via applicationDidEnterBackground and applicationWillEnterForeground seems tedious.

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.

Receiving Delegate Methods for iAd Banners iOS 7

In iOS 7, ADBannerView no longer needs to be created manually. Instead, they can be requested with a simple self.canDisplayBannerAds = YES;
Now, I cannot set my View Controller as the banner delegate because there is no banner for me to access (to my knowledge).
I need to know when the banner is tapped and when that action is dismissed so I can properly pause/start my Sprite Kit game.
How am I supposed to have these delegate methods called so I can properly respond to the user's actions?
AFAIK, there is nothing in the UIView Controller iAD Additions that explains how to set the delegate for the banners.
Do I need to create the banners manually, or is there a way to achieve this while still using the newer API's?
Unfortunately, if you want to use the delegate methods, you will need to set up your iAd Banner manually. Even if you make your vc the delegate, by just using self.canDisplayBannerAds = YES, will not call the methods you need. In my sprite kit game, I made all the banners manually so I could take care of pausing the game and going to the background. Making them give you the control you are looking for. Good luck.

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.

Gamecenter init/authentication makes SpriteKit's sprite movement lagging

I have a simple scenario (default SpriteKit template): one ViewController and a MyScene SpriteKit scene.
In my ViewController I managed in viewDidLoad the gamecenter initialization but my scene after start immediatelly starts a rather quick sprite movement infinitely (a background parallax scrolling).
Everything works correctly but until GameCenter goes through the authentication procedure my sprite movement lags, breaks, not running fluently.
What practice can I have to minimize this (with keeping the parallax sprite movement running)?
I'm testing this on iPhone4 device (IOS7.03)
GameCenter authentication is actually something that has been causing lag in games for awhile. There are a couple ways people try to get around it, and it's really depends on the app and programmers taste.
Pause the game during GameCenter authentication
This is the easiest way typically, and pretty straightforward.
Put the authentication on another thread
If you desire a fluid option from menu to gameplay, this would be the route to go.
Just use GCD to start a new thread and run the GameCenter authentication in it.
Hope this helps. There might be a couple of other ways, but these are the two I've seen the most. I typically just use the first method.

Resources