Mr.*_*oon 5 ios sprite-kit skspritenode swift
我正在使用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)
Run Code Online (Sandbox Code Playgroud)
任何效果都足够了,可能是脉冲效应,或按下时发光.我搜索过,但我在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)))
}
Run Code Online (Sandbox Code Playgroud)
该函数AddChildFadeIn在类中定义:singleton
任何帮助深表感谢!
您可能想看看这个线程How can you create a giga around a sprite via SKEffectNode,其中一些用户建议使用SKEffectNode。然而,这需要大量的 CPU 能力才能完成。
还有建议使用 SKShapeNode,这也可能存在性能问题,可以在此处进行进一步阅读Sprite Kit 中 SKShapeNode 的性能较差。
| 归档时间: |
|
| 查看次数: |
2696 次 |
| 最近记录: |