I have the function that moves an object and runs animation on move:
func animateMove(move: MoveTo, completion: () -> ()) {
let object = move.object
let spriteName = "\(object.spriteName)\(move.direction.name)"
let textures = TextureCache.loadTextures(spriteName)
let animate = SKAction.animateWithTextures(textures, timePerFrame: moveDuration/NSTimeInterval(textures.count))
let point = pointForColumn(move.column, row: move.row)
let move = SKAction.moveTo(point, duration: moveDuration)
move.timingMode = .Linear
let group = SKAction.group([move, animate])
object.sprite!.removeAllActions()
object.sprite!.runAction(group, completion: completion)
}
Also I have the cacher:
class TextureCache {
...
static func loadTextures(name: String) -> [SKTexture] {
let atlas = "\(name).atlas"
return TextureCache.sharedInstance.loadTexturesFromAtlas(atlas, name: name)
}
private func loadTexturesFromAtlas(atlas: String, name: String) -> [SKTexture] {
if let textures = textureDictionary["\(atlas):\(name)"] {
return textures
}
let textureAtlas = SKTextureAtlas(named: atlas)
var textures = [SKTexture]()
for i in 0..<textureAtlas.textureNames.count {
textures.append(SKTexture(imageNamed: "\(name)\(i)"))
}
textureDictionary["\(atlas):\(name)"] = textures
return textures
}
So, the problem is that during first call fps drops significantly and CPU time increases, for example: move object to the left - from 30 fps it drops to 8 fps.
sizeproperty, but you said that way didn't worked either. Personally, I can't reproduce what you are saying,so I can't comment more on this. Also I am not aware of your current setup, so it can happen that the error is on your side. As last resort, try to reproduce what you are saying in an empty project. Just use textures / atlas needed and see if you still getting that crash. If not,double check your code logic. - Whirlwind