我正在使用Swift编码Xcode 6中的第一个SpriteKit应用程序。现在我已经通过透明png文件制作了一些不错的按钮。但是我试图在按下按钮时显示视觉效果。在按下时向SKSpriteNode添加视觉效果
例子我怎么现在显示静态按钮:
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
任何帮助,非常感谢!
什么是Button? addChildFadeIn定义在哪里? – 2015-02-24 15:05:31
我已经使用该信息编辑了帖子。你可以帮帮我吗? – 2015-02-24 17:53:11
不幸的是我不知道SpriteKit。我更新了您的标题和标签,以便您的问题能够被可以回答的人更容易发现。 – 2015-02-24 17:59:05