ios - Game Center "Done" button issue? -
the "done" button in game center not dismiss controller. code dismiss view controller same everywhere look. i've looked @ similar questions on here no luck. can me?
gamescene.swift (this serves start menu )
class gamescene: skscene, gkgamecentercontrollerdelegate { var startbtn = skspritenode(imagenamed: "play button") var title = sklabelnode(fontnamed: "avenirnext-ultralight") var leaderboardbuttonimage = skspritenode(imagenamed: "leaderboard button") override func didmovetoview(view: skview) { let bounds = uiscreen.mainscreen().bounds self.scene?.size = cgsize(width: bounds.size.width, height: bounds.size.height) scene?.backgroundcolor = uicolor.whitecolor() startbtn.position = cgpoint(x: self.frame.width / 2 - 100, y: self.frame.height / 2) startbtn.size = cgsize(width: 140, height: 55) self.addchild(startbtn) leaderboardbuttonimage.position = cgpoint(x: self.frame.width / 2 + 100, y: self.frame.height / 2) leaderboardbuttonimage.size = cgsize(width: 140, height: 55) self.addchild(leaderboardbuttonimage) } func showleaderboard() { let vc = self.view?.window?.rootviewcontroller let gc = gkgamecenterviewcontroller() gc.viewstate = gkgamecenterviewcontrollerstate.leaderboards gc.leaderboardidentifier = "i removed part" vc!.presentviewcontroller(gc, animated: true, completion: nil) } func gamecenterviewcontrollerdidfinish(gamecenterviewcontroller: gkgamecenterviewcontroller) { gamecenterviewcontroller.dismissviewcontrolleranimated(true, completion: nil) } override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) { /* called when touch begins */ touch in (touches ) { let location = touch.locationinnode(self) if (startbtn.containspoint(location)) { self.view?.presentscene(gameplayscene(), transition: sktransition.crossfadewithduration(1.0)) gameplayscene().scalemode = .resizefill startbtn.removefromparent() title.removefromparent() leaderboardbuttonimage.removefromparent() } if (leaderboardbuttonimage.containspoint(location)) { showleaderboard() } } } }
in func showleaderboard(), had add line gc.gamecenterdelegate = self made "done" button work.
i hope other people have same problem see potential fix.
func showleaderboard() { let vc = self.view?.window?.rootviewcontroller let gc = gkgamecenterviewcontroller() gc.viewstate = gkgamecenterviewcontrollerstate.leaderboards gc.gamecenterdelegate = self gc.leaderboardidentifier = "i removed part" vc!.presentviewcontroller(gc, animated: true, completion: nil) }
Comments
Post a Comment