有时在SpriteKit中,帧的动画不起作用:有一个白色矩形,然后是来自地图集的图像,依此类推。当我再次停止并运行时,动画适用于每一帧。你知道为什么会这样吗?
框架是文件夹中的常规png,我手动添加“.atlas”并将其拖动到XCode。这是代码:
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
}