将UIButton的属性赋给SpriteKit中的SKSpriteNode

我想知道是否有一种方法来给一个UIButton的属性,例如一旦它被按下就变暗button,…给SKSpiteNode因为SKSpiteNode有更多的自定义,因为我使用的是SpriteKit 。 我见过其他1个这样的问题,但没有任何答案。 这里是我必须创buildSKSpriteNode和检测触摸它的代码:

 import SpriteKit class StartScene: SKScene { var startButton = SKSpriteNode() override func didMoveToView(view: SKView) { startButton = SKSpriteNode(imageNamed: "playButton") startButton.size = CGSize(width: 100, height: 100) startButton.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 - 50) self.addChild(startButton) } override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { /* Called when a touch begins */ for touch in touches { let location = touch.locationInNode(self) if startButton.containsPoint(location){ // When it has been selected } } } //... 

请帮忙。 在此先感谢…安东

我一直通过添加代码来实现这个开始,并触及结束的方法。 在这些方法的内部,我简单地将精灵颜色设置为黑色,然后更改颜色混合因子。 让我知道这是否适合你!

  //This will hold the object that gets darkened var target = SKSpriteNode() //This will keep track if an object is darkened var have = false override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { var first = touches.first as! UITouch var location:CGPoint = first.locationInNode(self) touchP = location mouse.position = touchP var node:SKNode = self.nodeAtPoint(location) if let button = node as? SKSpriteNode { target = button have = true } else { have = false } if (have == true) { target.color = UIColor.blackColor() target.colorBlendFactor = 0.2 } } override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { if (havet == true) { target.color = UIColor.blackColor() target.colorBlendFactor = 0 target = SKSpriteNode() have = false } }