【发布时间】:2015-02-24 14:54:35
【问题描述】:
我正在 Xcode 6 中开发我的第一个 SpriteKit 应用程序,使用 Swift 进行编码。现在我用透明的 png 文件制作了一些不错的按钮。但我试图在按下按钮时显示视觉效果。
我现在如何显示静态按钮的示例:
let playButton = Button(imageNamed:"playButton")
playButton.position = CGPointMake(self.size.width/2, self.size.height/2 - playButton.size.height * 2.5 - displacement)
self.sharedInstance.addChildFadeIn(playButton, target: self)
任何效果都足够了,可能是脉冲效果,或者按下时发光。我已经搜索过了,但在 Swift 中我真的找不到任何东西。
编辑:更多信息
class Button: SKSpriteNode {
init(imageNamed: String) {
let texture = SKTexture(imageNamed: imageNamed)
// have to call the designated initializer for SKSpriteNode
super.init(texture: texture, color: nil, size: texture.size())
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
self.runAction(SKAction.scaleTo(1.3, duration: kButtonFadingSpeed))
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
self.runAction(SKAction.scaleTo(1.3, duration: kButtonFadingSpeed))
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
self.runAction(SKAction.scaleTo(1.0, duration: kButtonFadingSpeed))
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
func addChildFadeIn(node: SKNode, target: SKNode) {
node.alpha = 0
target.addChild(node)
node.runAction(SKAction.fadeAlphaTo(1.0, duration: NSTimeInterval(kAddChildSpeed)))
}
函数AddChildFadeIn在类中定义:singleton
非常感谢任何帮助!
【问题讨论】:
-
什么是按钮? addChildFadeIn 在哪里定义?
-
我已经使用该信息编辑了帖子。你能帮帮我吗?
-
不幸的是我不知道 SpriteKit。我已经更新了你的标题和标签,让可以回答的人更容易发现你的问题。
-
我能想到的最简单的效果就是用这个method给节点着色
标签: ios swift sprite-kit skspritenode