作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Var 按钮。
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)
当我点击它并发出声音时,如何添加按钮效果,如按钮颜色灯。
最佳答案
一种方法是您可以在选择按钮时更改图像。
像这样进入您的 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)
关于swift - 如何在swift SKSpriteNode中添加按钮效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206766/
我是一名优秀的程序员,十分优秀!