ios - How to go back to main scene when my game paused in sprite kit -
when pause game have pause scene.
i put there 3 buttons :
rateapp button
backtomain button.
resumegame button.
what happens:
rateapp button working.
resumegame button working.
not working :
- backtomain button.
why?
because game still pause.
pausegame function
func pausegame() { ispause = true self.view?.paused = true pointslabel.hidden = true boocharacter.hidden = true pausebutton.hidden = true if #available(ios 9, *) { recordbutton.hidden = true } pausescreen = skspritenode() pausescreen.name = "pausescreen" pausescreen.position = cgpointmake(self.size.width/2, self.size.height/2) pausescreen.color = uicolor.blackcolor() pausescreen.alpha = 0.9 pausescreen.size = cgsizemake(1242,2208) addchild(pausescreen) pauselable.text = "pause" pauselable.fontsize = 75 pauselable.fontname = "futura-medium" pauselable.fontcolor = uicolor(red:0.98, green:0.82, blue:0.32, alpha:1.0) pauselable.position = cgpoint(x: self.size.width/2, y: self.size.height/2 + 170) addchild(pauselable) continuebutton.name = "countinuebutton" continuebutton.position = cgpoint(x: self.size.width/2, y: self.size.height/2) continuebutton.size = cgsizemake(100, 100) addchild(continuebutton) homebutton.position = cgpoint(x: self.size.width/2 - 50, y: self.size.height/2 - 200) homebutton.size = cgsizemake(70 , 70) homebutton.name = "homebutton" homebutton.runaction(skaction.movetoy(90, duration: 0.6)) homebutton.removefromparent() addchild(homebutton) ratebutton.position = cgpoint(x: self.size.width/2 + 50, y: self.size.height/2 - 200) ratebutton.size = cgsizemake(70 , 70) ratebutton.name = "ratebutton" ratebutton.runaction(skaction.movetoy(90, duration: 0.6)) ratebutton.removefromparent() addchild(ratebutton) }
updated :
let scene = gamescene(filenamed:"gamescene") var homebutton : uibutton! var ratebutton : uibutton! override func viewdidload() { super.viewdidload() if (scene != nil) { // configure view. let skview = self.view as! skview //skview.showsfps = true //skview.showsnodecount = true /* sprite kit applies additional optimizations improve rendering performance */ skview.ignoressiblingorder = true //skview.showsphysics = true nsnotificationcenter.defaultcenter().addobserver(self, selector: "goback", name: "gobackclick", object: nil); /* set scale mode scale fit window */ scene!.scalemode = .aspectfill skview.presentscene(scene) } } override func viewwilllayoutsubviews() { super.viewwilllayoutsubviews() homebutton.frame = cgrectmake(self.view!.frame.size.width/2 - 50, self.view!.frame.size.height/2 - 200, 70, 70) homebutton.setimage(uiimage(named: "homebuttonpause.png"), forstate: uicontrolstate.normal) homebutton.addtarget(self, action: "pressedhomebutton", forcontrolevents: .touchupinside) ratebutton.frame = cgrectmake(self.view!.frame.size.width/2 + 50, self.view!.frame.size.height/2 - 200, 70, 70) ratebutton.setimage(uiimage(named: "ratebuttonpause.png"), forstate: uicontrolstate.normal) ratebutton.addtarget(self, action: "pressedratebutton", forcontrolevents: .touchupinside) self.view.addsubview(homebutton) self.view.addsubview(ratebutton) } func pressedhomebutton(sender: uibutton!) { //back main screen sktaudio.sharedinstance().playsoundeffect("click button sound.mp3"); nsnotificationcenter.defaultcenter().removeobserver(self, name: "gobackclick", object: nil) self.dismissviewcontrolleranimated(true, completion: { }); } func pressedratebutton(sender: uibutton!) { //rate app sktaudio.sharedinstance().playsoundeffect("click button sound.mp3"); uiapplication.sharedapplication().openurl(nsurl(string: "https://itunes.apple.com/us/app/boo-adventure/id1030047247?ls=1&mt=8")!) //add link here print("rate app!") }
i trying create 2 subviews 2 button (home button , rate button) , created uibuttons them xcode return error!
pausegame function updated!
func pausegame() { ispause = true gameviewcontroller().continuegame() pointslabel.hidden = true boocharacter.hidden = true pausebutton.hidden = true if #available(ios 9, *) { recordbutton.hidden = true } pausescreen = skspritenode() pausescreen.name = "pausescreen" pausescreen.position = cgpointmake(self.size.width/2, self.size.height/2) pausescreen.color = uicolor.blackcolor() pausescreen.alpha = 0.9 pausescreen.size = cgsizemake(1242,2208) addchild(pausescreen) pauselable.text = "pause" pauselable.fontsize = 75 pauselable.fontname = "futura-medium" pauselable.fontcolor = uicolor(red:0.98, green:0.82, blue:0.32, alpha:1.0) pauselable.position = cgpoint(x: self.size.width/2, y: self.size.height/2 + 170) addchild(pauselable) continuebutton.name = "countinuebutton" continuebutton.position = cgpoint(x: self.size.width/2, y: self.size.height/2) continuebutton.size = cgsizemake(100, 100) addchild(continuebutton) gameviewcontroller().viewwilllayoutsubviews() }
try take beginning of gamescene
func gotogamescene(){ let gamescene:gamescene = gamescene(size: self.view!.bounds.size) // create new scene let transition = sktransition.fadewithduration(1.0) // create type of transition (you can check in documentation more transtions) gamescene.scalemode = skscenescalemode.fill self.view!.presentscene(gamescene, transition: transition) }
if doesn't work let me know.
Comments
Post a Comment