我有个Var Button
var soundButton: SKSpriteNode! = nil细节就像。
soundButton = SKSpriteNode(imageNamed: "\(soundImg)")
soundButton.position = CGPoint(x: frame.size.width*0.08 , y:frame.size.width*0.08);
soundButton.size = CGSizeMake(frame.size.width*0.10,frame.size.width*0.10 )
self.addChild(soundButton)比我如何添加按钮效果,如按钮颜色灯,当我点击它,并作出声音也。
发布于 2015-05-13 06:12:45
这样做的一种方法是,您可以在选择按钮时更改图像。
像这样进入您的touchesBegan方法:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self. soundButton {
soundButton.texture = SKTexture(imageNamed: "soundSelected")
}
}
}如果您想要使用延迟转到另一个场景,并且需要转换,可以在if语句中使用以下代码:
let reveal = SKTransition.flipHorizontalWithDuration(0.5)
let letsPlay = playScene(size: self.size)
self.view?.presentScene(letsPlay, transition: reveal)https://stackoverflow.com/questions/30206766
复制相似问题