nix.codes
nix.codes

Reputation: 388

How to free scene until Interstitial is dismissed?

So I have a an app that uses interstitial ads. Specifically it is a a SpriteKit game written with Swift.

I have code setup that when the user presses the replay button from the game over scene an ad appears and then it changes back to the game scene to replay the game. Now where I am running into problems the scene changes while the interstitial ad is being displayed, sometimes this doesn't happen fast enough and user can tap the restart button again, causing the game to crash.

Is there a way to freeze the screen and ignore any taps while the ad is being called? And also to only have the scene change after the ad is dismissed?

The code when the restart button is pressed;

 if restartButton.contains(pointOfTouch) {
    score = 0
    ballMovementSpeed = 2
    displayAd()
    delay(2.0) {
    self.restartScene()
 }

I am a bit confused as to where the interstitialDelegate is placed. I am trying to implement func interstitialDidDismissScreen(ad: GADInterstitial!) {} to trigger a change back to my game scene and nothing happens when I dismiss the ad.

I have tried placing it in override func didMove(to view: SKScene){} as well as when the restart button is pressed and still won't work. This is how i have the ad being called

fun loadAndShow() {
  myAd = GADInterstitial()
  let requestI = GADRequest()
  myAd.setAdUnitID("adID")
  requestI.testDevices = [kGADSimulatorID, "test device"]
  myAd.delegate = self
  myAd.load(requestI)
}

func interstitialDidReceiveAd(_ ad: GADInterstitial) {
  if (self.myAd.isReady) {
    myAd.present(fromRootViewController: self)
  }
}

Upvotes: 0

Views: 691

Answers (1)

Chipster Chops
Chipster Chops

Reputation: 86

you can use delegate methods of admob so when interstitial is going to be shown you can remove the restart button or put a condition so that it would not work when ad is shown. Also to pause the game is also important if it is running using isPaused bool. https://developers.google.com/admob/ios/ad-events

Upvotes: 1

Related Questions