I am working on my first SpriteKit app in Xcode 6, coding in Swift. Now I have made some nice buttons from transparent png files. But I am trying to show a visual effect when the button is pushed.
Example how I now show a static button:
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)
Any effect would be enough, maybe a pulse effect, or glow on press. I've searched, but I can't really find anything in Swift.
edit: more info
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)))
}
The function AddChildFadeIn
is defined in class: singleton
Any help is much appreciated!