sometimes in SpriteKit, the animation of frames does not work: there is a white rectangle, then an image from the atlas, and so on. When I stop and run again, the animation works with every frame. Would you know why this happen?
The frames are regular pngs in a folder, I add ".atlas" manually and drag it to XCode. Here is the code :
var ball : SKSpriteNode!
var ballTurn : [SKTexture]!
ball = SKSpriteNode(texture: ballTurn[0])
ball.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
addChild(ball)
turningBall(ball, textures: ballTurn, str:"ballTurn")
func turningBall(theNode: SKSpriteNode, textures: [SKTexture], str:String) {
theNode.removeAllActions()
theNode.runAction(SKAction.repeatActionForever(
SKAction.animateWithTextures(textures,
timePerFrame: 0.05,
resize: false,
restore: true)),
withKey:str)
}
//the method to generate the frames from Blender
func generatorFrames(atlas:SKTextureAtlas, str:String) -> [SKTexture]{
var frames = [SKTexture]()
let count = atlas.textureNames.count
for var i=0; i<count; i++ {
var theName = ""
if i < 10 {
theName = str+"000\(i)"
} else {
theName = str+"00\(i)"
}
frames.append(atlas.textureNamed(theName))
}
return frames
}