3
嗨想了解如何創建視頻脈衝效果,如下面的視頻。如何在SKSpriteNode上創建脈衝效果?
https://www.youtube.com/watch?v=uiHj-KZWjpU
我也跟着張貼在視頻的鏈接;然而,我還沒有能夠達到同樣的效果。我在使用SKSpriteNode時遇到了麻煩。
最好我想能夠循環這個效果重複每一秒左右。
任何幫助將非常感謝!謝謝!
嗨想了解如何創建視頻脈衝效果,如下面的視頻。如何在SKSpriteNode上創建脈衝效果?
https://www.youtube.com/watch?v=uiHj-KZWjpU
我也跟着張貼在視頻的鏈接;然而,我還沒有能夠達到同樣的效果。我在使用SKSpriteNode時遇到了麻煩。
最好我想能夠循環這個效果重複每一秒左右。
任何幫助將非常感謝!謝謝!
這樣做的一個真正簡單的方法是讓您的按鈕圖像和右下方的輪廓圖像按鈕。然後在按鈕輪廓圖像上運行脈衝函數,瞧!它適用於任何形狀,您可以根據需要調整動作。這些通過場景編輯器添加,但只要輪廓圖像的Z位置低於按鈕,它們的添加方式就沒有區別。
class LevelMenu: SKScene {
private var button1 = SKSpriteNode()
private var button1Outline = SKSpriteNode()
private var button2 = SKSpriteNode()
private var button2Outline = SKSpriteNode()
private var button3 = SKSpriteNode()
private var button3Outline = SKSpriteNode()
override func didMove(to view: SKView) {
if let button1 = self.childNode(withName: "button1") as? SKSpriteNode {
self.button1 = button1
}
if let button2 = self.childNode(withName: "button2") as? SKSpriteNode {
self.button2 = button2
}
if let button3 = self.childNode(withName: "button3") as? SKSpriteNode {
self.button3 = button3
}
if let button1Outline = self.childNode(withName: "button1Outline") as? SKSpriteNode {
self.button1Outline = button1Outline
}
if let button2Outline = self.childNode(withName: "button2Outline") as? SKSpriteNode {
self.button2Outline = button2Outline
}
if let button3Outline = self.childNode(withName: "button3Outline") as? SKSpriteNode {
self.button3Outline = button3Outline
}
}
func pulseAction(node: SKSpriteNode) {
let copyNode = node.copy() as! SKSpriteNode
copyNode.position = node.position
addChild(copyNode)
let scale = SKAction.scale(by: 1.75, duration: 0.4)
scale.timingMode = .easeInEaseOut
let wait = SKAction.wait(forDuration: 0.25)
let fadeOut = SKAction.fadeOut(withDuration: 0.15)
let fadeSeq = SKAction.sequence([wait, fadeOut])
let pulseGroup = SKAction.group([scale, fadeSeq])
copyNode.run(pulseGroup, completion: { copyNode.removeFromParent() })
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
pulseAction(node: button1Outline)
pulseAction(node: button2Outline)
pulseAction(node: button3Outline)
}
}
可以使用規模做到+褪色SKActions並在相同常(序列中的分組,而不是)運行它們。要延遲循環操作,請使用序列。 – Whirlwind
@Whirlwind哈哈哈,你的答案比我快一點。我花了20分鐘來創建那個愚蠢的動畫GIF;) –
@RonMyschuk呃,你其實並沒有和我一樣懶惰,並且做出了答案:D關於那個GIF ......這是很多時間。你有沒有試過OSX的Giphy Capture應用程序? – Whirlwind