I'm designing a game in iOS Swift.
I have a large texture-atlas of about 100 1920x1080p PNG's. When I call the functions it crashes the app due to memory pressure. When I disable the function my app runs just fine.
Can I prevent this crash by editing my code or is my texture-atlas just too big?
Code:
var waterWave: SKSpriteNode!
var waterWalkingFrames : [SKTexture]!
func addWater() {
let waterAnimatedAtlas = SKTextureAtlas(named: "water.atlas")
var waterFrames = [SKTexture]()
let numImages = waterAnimatedAtlas.textureNames.count
for var i=0; i<numImages; i++ {
let waterTextureName = "water_000\(i)"
waterFrames.append(waterAnimatedAtlas.textureNamed(waterTextureName))
}
self.waterWalkingFrames = waterFrames
let firstFrame = waterWalkingFrames[0]
self.water = SKSpriteNode(texture: firstFrame)
self.water.anchorPoint = CGPointMake(0.5, 0.5)
self.water.position = CGPointMake(CGRectGetMidX(self.frame), self.runningBar.position.y + (self.runningBar.size.height / 2) + 5)
self.water.size.width = self.frame.size.width
self.water.size.height = self.frame.size.height
self.water.zPosition = 7
self.addChild(self.water)
waterAnimation()
}
func waterAnimation() {
self.water.runAction(SKAction.repeatActionForever(
SKAction.animateWithTextures(waterWalkingFrames, timePerFrame: (1 / 60), resize: false, restore: true)), withKey:"surferBasic")
}