我在SpriteKit中有一个游戏,角色一直在使用一个动画来赋予他不断弹跳的错觉。
let frankieTexture = SKTexture(imageNamed: "image1.png")
let frankieTexture2 = SKTexture(imageNamed: "image2.png")
let frankieTexture3 = SKTexture(imageNamed: "image3.png")
let frankieBounceAnimation = SKAction.animate(with: [frankieTexture, frankieTexture2, frankieTexture3], timePerFrame: 0.3)
let makeFrankieBounce = SKAction.repeatForever(frankieBounceAnimation)
frankie = SKSpriteNode(texture: frankieTexture)
frankie.position = CGPoint(x: self.frame.midX - 250, y: self.frame.midY - 450)
frankie.size = CGSize(width: frame.size.width * 0.25, height: frame.size.height * 0.25)
frankie.run(makeFrankieBounce)
然后在touches下开始,当用户点击屏幕时,我想中断该动画并将其替换为另一个动画。这个:
let frankieOtherAnimationTexture1 = SKTexture(imageNamed: "OtherAnimation1.png")
let frankieOtherAnimationTexture2 = SKTexture(imageNamed: "OtherAnimation2.png")
let frankieOtherAnimationTexture3 = SKTexture(imageNamed: "OtherAnimation3.png")
let frankieOtherAnimationTexture4 = SKTexture(imageNamed: "OtherAnimation4.png")
let frankieOtherAnimationAnimate = SKAction.animate(with: [frankieOtherAnimationTexture1, frankieOtherAnimationTexture2, frankieOtherAnimationTexture3, frankieOtherAnimationTexture4], timePerFrame: 0.2)
let makeFrankieOtherAnimation = SKAction.repeat(frankieOtherAnimationAnimate, count: 1)
如何让repeatForever暂停并运行第二个动画,然后重新启动?我玩过一些if,then语句,似乎无法做到... 预先感谢!
答案 0 :(得分:0)
哇!对不起,大家。。。几个小时后,我意识到我忘记了
Frankie.run(SKAction)
在我的代码中,在.touchesBegan方法中播放第二个动画之后...它运行良好,而不必暂停永远重复的第一个动画。