To use Sheets or Not?

Hi,

About 95% or more of my assets are loaded only once at startup.

Aside from loading only one larger file, Will I still get more benefit from using Atlas (sheets) over individual handling in terms of memory and performance? I did a rough comparison, adding up all the file sizes of individual images vs the single sheet generated by Texture Packer, they are roughly the same. Also, since the assets are loaded only once at start-up (be it single large sheet or individual images) , is there performance difference during gameplay?

Cheers

Hi,

I have not performed any benchmarks on Corona SDK - so I must admit that I can offer no “hard” facts about it.

Loading time

One big advantage is that loading the asset is reduced to a single file load, which might be faster than loading single files. It’s also possible to reduce transparency to save some memory. - That’s the loading time benefit you already mentioned

Performance

Using a sprite sheet allows you to batch draw calls. This means that instead of the following sequence (inside Corona’s game engine + OpenGL ES, not visible to you)

  • set texture1 
  • set source coordinates  for sprite1
  • set coordinates for sprite1
  • draw sprite1
  • set texture2
  • set source coordinates  for sprite2
  • set coordinates for sprite2
  • draw sprite2

With single sprites your are sending a whole bunch of commands to OpenGL, some of them (e.g. changing the texture) might lead to delay because OpenGL and Corona might be forced to synchronize. I am writing “might” because this highly depends on the OpenGL implementation.

What is certain about it is that it causes way more calls to OpenGL which is expensive.

You can simplify the call sequence dramatically:

  • build source coordinate list (once, when sprites are added or removed)
  • update destination coordinate list 
  • set source coordinates
  • set destination coordinates
  • set atlas texture
  • draw

Now OpenGL runs in asynchronous mode, performs the drawing while the Corona could do other things like collision checking etc.

I’ve created a small video which might be more fun to watch:

https://www.codeandweb.com/what-is-a-sprite-sheet-performance

I got it Andreas, nice illustration.  Thanks for the feedback.

Although I have made two versions of one of my heaviest levels for comparison, one with individual asset management, the other using Atlas and I didn’t see any noticeable difference in load times and performance, (probably because the device is “fast” enough that I don’t see difference),  I guess it’s generally a good practice then, to use sheets over individual assets.

I also realized there are other added benefits of using sheets - Organizing image assets in one place, especially if you have a lot of levels.  In my case, some levels have their own assets specific to that level, and naming them can be a nightmare!  

On a side note, I like Texture Packer’s neat feature of auto-updating an image within the sheet as you change it in PhotoShop (or any image editor), plus the capability of creating scaled-down versions of the images.   

Thanks!

Santi

I also realized there is an added benefit of organizing image assets in one place, especially if you have a lot of levels.

Cheers,

Santi

Hi,

I have not performed any benchmarks on Corona SDK - so I must admit that I can offer no “hard” facts about it.

Loading time

One big advantage is that loading the asset is reduced to a single file load, which might be faster than loading single files. It’s also possible to reduce transparency to save some memory. - That’s the loading time benefit you already mentioned

Performance

Using a sprite sheet allows you to batch draw calls. This means that instead of the following sequence (inside Corona’s game engine + OpenGL ES, not visible to you)

  • set texture1 
  • set source coordinates  for sprite1
  • set coordinates for sprite1
  • draw sprite1
  • set texture2
  • set source coordinates  for sprite2
  • set coordinates for sprite2
  • draw sprite2

With single sprites your are sending a whole bunch of commands to OpenGL, some of them (e.g. changing the texture) might lead to delay because OpenGL and Corona might be forced to synchronize. I am writing “might” because this highly depends on the OpenGL implementation.

What is certain about it is that it causes way more calls to OpenGL which is expensive.

You can simplify the call sequence dramatically:

  • build source coordinate list (once, when sprites are added or removed)
  • update destination coordinate list 
  • set source coordinates
  • set destination coordinates
  • set atlas texture
  • draw

Now OpenGL runs in asynchronous mode, performs the drawing while the Corona could do other things like collision checking etc.

I’ve created a small video which might be more fun to watch:

https://www.codeandweb.com/what-is-a-sprite-sheet-performance

I got it Andreas, nice illustration.  Thanks for the feedback.

Although I have made two versions of one of my heaviest levels for comparison, one with individual asset management, the other using Atlas and I didn’t see any noticeable difference in load times and performance, (probably because the device is “fast” enough that I don’t see difference),  I guess it’s generally a good practice then, to use sheets over individual assets.

I also realized there are other added benefits of using sheets - Organizing image assets in one place, especially if you have a lot of levels.  In my case, some levels have their own assets specific to that level, and naming them can be a nightmare!  

On a side note, I like Texture Packer’s neat feature of auto-updating an image within the sheet as you change it in PhotoShop (or any image editor), plus the capability of creating scaled-down versions of the images.   

Thanks!

Santi

I also realized there is an added benefit of organizing image assets in one place, especially if you have a lot of levels.

Cheers,

Santi