我希望有一个动画,我创建的重复运行之间的每一个动画之间的随机间隔,而用户正在使用应用程序。
我创建了一个做动画的函数。
func Yawn () {
Yawn1.append(character_atlas.textureNamed("1.png"))
Yawn1.append(character_atlas.textureNamed("2.png"))
Yawn2.append(character_atlas.textureNamed("3.png"))
Yawn2.append(character_atlas.textureNamed("4.png"))
Character_animate = SKSpriteNode(texture: Yawn1[0])
Character_animate2 = SKSpriteNode(texture: Yawn2[0])
Character_animate.size = CGSize(width: self.size.width/6.3, height: self.size.height/5.6)
Character_animate2.size = CGSize(width: self.size.width/6.3, height: self.size.height/5.6)
Character_animate2.position = CGPoint(x: self.frame.width/2, y: self.frame.height*0.90)
Character_animate.position = CGPoint(x: self.frame.width/2, y: self.frame.height*0.90)
Character_animate.zPosition = 3
Character_animate2.zPosition = 3
addChild(Character_animate)
addChild(Character_animate2)
var action1 = SKAction.repeatAction(SKAction.animateWithTextures(Yawn1, timePerFrame: 0.4), count: 3)
var action2 = SKAction.repeatAction(SKAction.animateWithTextures(Yawn2, timePerFrame: 1), count: 4)
var action3 = SKAction.sequence([action1,action2])
var action4 = SKAction.runBlock({self.Character_animate.removeFromParent()})
var action5 = SKAction.runBlock({self.Character_animate2.removeFromParent()})
var action6 = SKAction.sequence([action4,action5])
Character_animate2.runAction(action3,completion: {
self.runAction(action6)
})
}发布于 2016-06-05 11:00:17
您可以使用一个NSTimer并使用一个随机数来定义函数Yawn的每个激发之间的NSTimerInterval。
let randomNumber = Int(arc4random_uniform(10)) // This will return random number from 0 to 9 (10-1)
NSTimer.scheduledTimerWithTimeInterval(randomNumber, target: self, selector: #selector(YourVC.Yawn) , userInfo: nil, repeats: true)https://stackoverflow.com/questions/37640380
复制相似问题