ios - Large texture atlas causes termination due to memory pressure -
i'm designing game in ios swift.
i have large texture-atlas of 100 1920x1080p png's. when call functions crashes app due memory pressure. when disable function app runs fine.
can prevent crash editing code or texture-atlas big?
code:
var waterwave: skspritenode! var waterwalkingframes : [sktexture]! func addwater() { let wateranimatedatlas = sktextureatlas(named: "water.atlas") var waterframes = [sktexture]() let numimages = wateranimatedatlas.texturenames.count 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") }
animation expensive if optimize textures in way (e.g. changing texture format). 1920x1080px texture occupies 8 megabytes if using standard rgba8888 format when stored in ram memory , said, because of device memory limitation, app crash @ point.
in situation, if animation allows this, way make video of it, , use skvideonode play it. recommended in docs because using textures can expensive in situations:
like other node, can put movie node anywhere inside node tree , sprite kit render properly. example, might use video node animate visual behaviors expensive define using collection of textures.
this suitable way background animations, cut scenes, intros ...
for looping video can use avplayer initialize skvideonode it. read more here. suggest because skvideonode limited play() , pause() methods controlling video playback.
hope helps , make sense!
Comments
Post a Comment