0

I’ll start with I’m new to swift and Xcode, as well as stack overflow so forgive me if I break some rules. I have a button in my gamescene and I’m trying to call a function when it is click. I’ve tried 2 things which I’ll add here. Nothing online has been helpful. I used the sprite kit, the button is a spritenode that doesn’t have its Own class. Any help would be appreciated

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            
            for touch: AnyObject in touches {
                let location = touch.location(in:self)
                if attackBut.contains(_:location) {
                    player.texture = playF2
                    punc(dude: player, texts: playaFrames)
                }
            }
            /*
            let touch = touches.first
            
            if let location = touch?.location(in: self) {
                let nodesArray = self.nodes(at: location)
                
                if nodesArray.first?.name == "attackBut" {
                    player.run(teste)
                    punc(dude: player, texts: playaFrames)
                }
            }
            */
        }

The commented section is another method I tried.

I’m also on my phone so formatting may be weird. Thank you!

  • Please look at this: https://stackoverflow.com/questions/19082202/setting-up-buttons-in-skscene – Nikodem Apr 27 '22 at 17:35
  • Unfortunately that code is outdated and I don’t know enough to convert it into code usable in Xcode 9.4. I appreciate the help though! – Ben Gordos Apr 27 '22 at 17:58

0 Answers0