我正在使用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