Sprite plates taking up huge amounts of memory; crashes lower-end devices

I have an endless runner game I’m making where your a dinosaur trying to escape from danger. One of the powerups I have is a pterodactyl that comes and picks you up then drops you farther along.

The problem is, when I load the plate up, it takes up over 8mb of texture memory. That was after I cut out nearly half the frames (went from 80 frames down to 47). With the original it took up over 16 mb of texture memory.

The cut down sprite plate is only 281 kb, how is it taking up that much space? Does anyone have any optimization tips?

Here is how I’m creating the plate and the sequences (they’re in functions because I call them from another .lua file):

local get\_PteraSpriteSheetData = function()  
 local pteraSpriteSheetData = {  
 width = 171,  
 height = 171,  
 numFrames = 50,  
 sheetContentWidth = 1710,  
 sheetContentHeight = 855 }  
 return pteraSpriteSheetData  
end  
  
local get\_PteraSequenceData = function()  
 local pteraSequenceData = {  
 {name = "carrying", start = 1, count = 36, time = 1500},  
 {name = "diving", start = 37, count = 10, time = 1500, loopCount = 1, loopDirection = "bounce"} }  
 return pteraSequenceData  
end  

And in the game:

 local pteraSpriteOptions = animationData.get\_PteraSpriteSheetData()  
 local pteraSheet = graphics.newImageSheet(\_G.graphicsPath.."ptera\_frames\_plate.png", pteraSpriteOptions)  
 local ptera = display.newSprite( pteraSheet, animationData.get\_PteraSequenceData() )  

Any help would be greatly appreciated.

-Treb [import]uid: 181948 topic_id: 33272 reply_id: 333272[/import]

PNGs are compressed, pretty similarly to .zip files. The GPU doesn’t understand compressed assets, and requires uncompressed resources (or PVR compressed files since the iOS has a hardware PVR decoder), and so when you load an image, it decompresses on load.

Because of this, and because Corona focusses on the most common image bitdepth (32 Bit RGBA8888), the math for determining the memory needed for a texture resource on the GPU is: (Height * Width * 4) bytes. It’s a lot, and you generally want to try to be conservative on texture resources as, aside from audio, it’s probably the easiest way to completely destroy any sort of memory budget you planned on having.

At some point you can try to push Corona to support the RGBA4444 format, but that suffers from only 16 shades per channel, which makes gradients look like garbage. Though it uses half the texture memory as a 32 bit format. Overall, you may want to simply optimize your atlases (texture plate as you called it), and find a way to drop frames, and load only the atlases you need in a given scene. [import]uid: 134101 topic_id: 33272 reply_id: 132206[/import]

Thanks, it makes sense now. I’ll do another culling round on my sprite sheets and see if I can be a bit more frugal with my asset loading.

-Treb [import]uid: 181948 topic_id: 33272 reply_id: 132209[/import]

PNGs are compressed, pretty similarly to .zip files. The GPU doesn’t understand compressed assets, and requires uncompressed resources (or PVR compressed files since the iOS has a hardware PVR decoder), and so when you load an image, it decompresses on load.

Because of this, and because Corona focusses on the most common image bitdepth (32 Bit RGBA8888), the math for determining the memory needed for a texture resource on the GPU is: (Height * Width * 4) bytes. It’s a lot, and you generally want to try to be conservative on texture resources as, aside from audio, it’s probably the easiest way to completely destroy any sort of memory budget you planned on having.

At some point you can try to push Corona to support the RGBA4444 format, but that suffers from only 16 shades per channel, which makes gradients look like garbage. Though it uses half the texture memory as a 32 bit format. Overall, you may want to simply optimize your atlases (texture plate as you called it), and find a way to drop frames, and load only the atlases you need in a given scene. [import]uid: 134101 topic_id: 33272 reply_id: 132206[/import]

Thanks, it makes sense now. I’ll do another culling round on my sprite sheets and see if I can be a bit more frugal with my asset loading.

-Treb [import]uid: 181948 topic_id: 33272 reply_id: 132209[/import]