ios - Using TouchesMoved in Swift 2 -


i'm making spritekit game in xcode using swift. want make custom buttons in menu, , i'm following this tutorial it. everything's working fine except touchesmoved function.

override func touchesmoved(touches: nsset, withevent event: uievent) { var touch: uitouch = touches.allobjects[0] uitouch var location: cgpoint = touch.locationinnode(self)  if defaultbutton.containspoint(location) {     activebutton.hidden = false     defaultbutton.hidden = true } else {     activebutton.hidden = true     defaultbutton.hidden = false } } 

apparently, "touches.allobjects[0] uitouch" doesn't work anymore in swift 2. i've searched alternatives, haven't found works. how replace line of code?

for reason tutorial using nsset rather set<uitouch> in touchesmoved. wonder if translated tutorial objective-c swift, , missed updating them?

func touchesmoved(_ touches: set<uitouch>,         withevent event: uievent?) 

touchesmoved - apple docs

notice touches argument of type nsset in code, , apple docs have set<uitouch>.

once switch set<uitouch>, try using touches.first as! uitouch

be careful if can nil, i'm not familiar user input functions on ios.

if allow multitouch later you'll need check entire set, rather grabbing first (and only) uitouch element.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -