ios - SpriteKit fps drops at first animation call -
i have function moves object , 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 have 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]() in 0..<textureatlas.texturenames.count { textures.append(sktexture(imagenamed: "\(name)\(i)")) } texturedictionary["\(atlas):\(name)"] = textures return textures }
so, problem during first call fps drops , cpu time increases, example: move object left - 30 fps drops 8 fps.
the problem on side in cacher, was:
let textureatlas = sktextureatlas(named: atlas) var textures = [sktexture]() in 0..<textureatlas.texturenames.count { textures.append(sktexture(imagenamed: "\(name)\(i)")) }
now:
let textureatlas = sktextureatlas(named: atlas) var textures = [sktexture]() in 0..<textureatlas.texturenames.count { let texture = textureatlas.texturenamed("\(name)\(i)") texture.size() textures.append(texture) }
Comments
Post a Comment