在多个SKTextures之间淡入淡出,SKSpriteKit



新年快乐!我正在尝试使用序列 SKAction 在多个 SKTextures 中淡入淡出,但我不确定该怎么做。我目前拥有它的方式在纹理之间的更改期间没有影响,如果可能的话,这就是我正在寻找的。谢谢

var playButtonAnimation: SKAction
var playButtonFadeIn: SKAction
var playButtonFadeOut: SKAction
var playButtonTextures:[SKTexture] = []
for i in 1...7 {
playButtonTextures.append(SKTexture(imageNamed: "button(i)"))
}
playButtonAnimation = SKAction.animate(with: playButtonTextures, timePerFrame: 3.0)
playButtonFadeIn = SKAction.fadeIn(withDuration: 1.0)
playButtonFadeOut = SKAction.fadeOut(withDuration: 1.0)
playButton.zPosition = -25
playButton.run(SKAction.sequence([playButtonFadeIn,playButtonAnimation,playButtonFadeOut]))
playButton.run(SKAction.repeatForever(playButtonAnimation))
addChild(playButton)

据我所知,你想使用 SKAction.group 操作来完成你需要做的事情。

目前,此代码将执行的操作是按纹理淡入和淡出:

var playButtonAnimation: SKAction
var playButtonFadeIn: SKAction
var playButtonFadeOut: SKAction
var playButtonTextures:[SKTexture] = []
for i in 1...7 {
playButtonTextures.append(SKTexture(imageNamed: "button(i)"))
}
playButtonAnimation = SKAction.animate(with: playButtonTextures, timePerFrame: 3.0)
playButtonFadeIn = SKAction.fadeIn(withDuration: 1.0)
playButtonFadeOut = SKAction.fadeOut(withDuration: 1.0)
let seq = SKAction.sequence([playButtonFadeIn,SKAction.wait(forDuration:1.0),playButtonFadeOut])
let grp = SKAction.group([SKAction.repeat(seq,count:7),playButtonAnimation])
playButton.zPosition = -25
playButton.run(SKAction.repeatForever(grp))
addChild(playButton)

最新更新