Why won't my game pause when an iAd is tapped on in Swift? -
what doing wrong? i'm trying game pause when ad tapped on still working in background. how pause? tried other ways pause scene it's not working me.
func didloadad(banner: adbannerview) { adbannerview.hidden = false } func bannerviewwillloadad(banner: adbannerview!) { println("ad load") } func bannerviewdidloadad(banner: adbannerview!) { adbannerview.center = cgpoint(x: adbannerview.center.x, y: view.bounds.size.height - view.bounds.size.height + adbannerview.frame.size.height / 2) adbannerview.hidden = false println("displaying ad") } func bannerviewactiondidfinish(banner: adbannerview!) { /* un-pause when ad closed */ if let scene = gamescene.unarchivefromfile("gamescene") as? gamescene { let skview = self.view skview skview.paused = false println("close ad") } } func bannerviewactionshouldbegin(banner: adbannerview!, willleaveapplication willleave: bool) -> bool { if let scene = gamescene.unarchivefromfile("gamescene") as? gamescene { let skview = self.view skview skview.paused = true println("leave application ad") //pause game here } return true } func bannerview(banner: adbannerview!, didfailtoreceiveadwitherror error: nserror!) { //move off bounds when add didn't load adbannerview.center = cgpoint(x: adbannerview.center.x, y: view.bounds.size.height + view.bounds.size.height) adbannerview.hidden = true println("ad not available") } //iad-----------------------------------------------------------------------------------------------------
i think problem here:
let skview = self.view skview skview.paused = true
and think should check if skview game view. self.view might ad view @ point.
to fix it, find view, instead of using self.
//at top of class var window:uiwindow? // inside method/function if let viewcontrollers = window?.rootviewcontroller?.childviewcontrollers { viewcontroller in viewcontrollers { if viewcontroller.iskindofclass(myviewcontrollerclass) { println("found it!!!") viewcontroller.paused = true } } }
Comments
Post a Comment