Как сделать кнопку используя SpriteKit в 2017 году?

spritekit

#1

Подскажите, как сделать кнопку используя SpriteKit в 2017 году
выдает ошибку в строчке …?

let location = touch.locationInNode(self)
Cannot call value of non-function type ‘CGFloat!’

Вот код годовой давности с этого форума представленный тов. ‘administrator’…

class GameScene: SKScene {
    var isTouching = false
    var button: SKNode!
    override func didMove(to view: SKView) {
        // Create a simple blue rectangle that's 100x40
        button = SKSpriteNode(color: SKColor.blue, size: CGSize(width: 100, height: 40))
        // Put it in the center of the scene
        button.position = CGPoint(x:self.frame.midX, y:self.frame.midY);
        self.addChild(button)
    }
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for touch: AnyObject in touches {
            // Get the location of the touch in this scene
            let location = touch.location(self)
            // Check if the location of the touch is within the button's bounds
            if button.containsPoint(location) {
                isTouching = true
                print("begun!")
            }
        }
    }
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        // Loop over all the touches in this event
        for touch: AnyObject in touches {
            // Get the location of the touch in this scene
            let location = touch.location(self)
            // Check if the location of the touch is within the button's bounds
            if button.containsPoint(location) {
                print("ended!")
                isTouching = false
            }
        }
    }
}

Даже на забугорных форумах все устарело.
Очень надо, очень…


#2

Вопрос решен. Кому-то будет полезно:slight_smile:

class GameScene: SKScene {
    var isTouching = false
    var button: SKNode!
    var loc: CGPoint!
    override func didMove(to view: SKView) {
        button = SKSpriteNode(color: SKColor.blue, size: CGSize(width: 100, height: 40))
        button.position = CGPoint(x:self.frame.midX, y:self.frame.midY);
        self.addChild(button)
    }
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
   
    for touch in (touches) {
        loc = touch.location(in: self)
        if button.contains(loc) {
            print("Работает!!!")
        }
    }

}

}