xcode - Why SKNode isn't reacting to touch in SpriteKit game? -


in order make pause in spritekit game made pause button. worker charm when wanted make scene pause , respond touch transitioning scene. function looked like this (p.s. pause = pause button) there other problems , decided make pause within main scene: playscene added pausebackground , resumebutton attached pause background , hided (declared resumebutton.hidden = true) function looks this:

override func touchesbegan(touches: nsset, withevent event: uievent) {     if self.onground {         self.speedy = -20.0         self.onground = false     }     touch: anyobject in touches {     let location = touch.locationinnode(self)         if self.nodeatpoint(location) == self.pause {         self.scene?.view?.paused = true         self.pausebackground.hidden = false         self.resumebutton.hidden = false         if self.nodeatpoint(location) == self.resumebutton {         self.pausebackground.hidden = true         self.resumebutton.hidden = true         self.scene?.view?.paused = false             }         }     } } 

it's interesting because worked scene transitions, xcode can't detect or ignore tap in pause button location. don't know why. please me? update: tried switch statement:

for touch: anyobject in touches {     let location = touch.locationinnode(self)         switch self.nodeatpoint(location) {         case self.pause:         self.scene?.view?.paused = true         self.pausebackground.hidden = false         self.resumebutton.hidden = false         case self.resumebutton:         self.pausebackground.hidden = true         self.resumebutton.hidden = true         self.scene?.view?.paused = false         default:         println()      } } 

sadly, it's not working either! have no idea why it's not detecting touch in location.

  1. give name pause button. control if pause button touched in touchesbegan printing name of touched node.

  2. control zposition of touched node , pause button. set zposition of pause button = 1000 , try touching it.

edit:

enter image description here

let's say, node node1 parent node of pausebutton.

node1.zposition = 100.0f; pausebutton.zposition = 200.0f; 

the continuebutton above scene

continuebutton.zposition = 250.0f; 

that means, zposition of pausebutton 200 above parent node node1. zposition of continuebutton (250) less zposition of pausebutton above scene, although zposition seems less (200). that's because zposition of pausebutton 300 above scene. zposition of parent node important control zpositions of children , other nodes of scene.

zposition of node relative parent node. have both buttons (pause , resume button) same parent node? best way control touched node, give each node name , zposition, , print (name , zposition nslog() / println()) in touchesbegan. know node touched , know zposition. , can correct zposition of each node, works need.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -