where to load imageSheet for sprites? (main.lua?)

Wondering where people generally load their imageSheet with their sprites.  

Loading them once in main.lua under a global variable would seem a good idea so they can be access from anywhere when that scene what’s to instantiate a sprite.  Seem reasonable?

Hi Greg,

I discourage use of globals in most cases. How about creating them as local in main.lua and then passing them to the scene as parameter(s)? Also, if you’re creating a ton of sprites for the entire game as a whole, it might not be wise to load them all in from the beginning, when only some are needed for a particular scene.

Brent

I create an image sheet per scene, and load them in the createScene method.

Then, they are only loaded if/when the user chooses to use that scene, instead of having a lot of images in memory for the entire life of the program.

Brent/schizoid2k - thanks - take you points re avoiding globals - just focusing on performance/memory usage however for a moment (for understanding purposes):

* I was only talking about create the single imageSheet (not the sprites). Just checking if you understood this.

* If you only have say 20-30 sprite images overall and you have them in a single imageSheet, AND assuming you will want to use some of these in each scene, THEN from a memory perspective have the imageSheet loaded once for the entire duration of the game would be the same as clearing and loading it again in each scene no?  In fact having to open it for each scene you might argue is a little slower.  (again just making the assumption there aren’t hundreds of sprites in the game)

Does this make sense?

Greg, Yes, if you have a small number of images and you plan on using them in multiple scenes, it would probably be best to load everything one time and refer to it. I probably would then either load them in main.lua as a global. There is an article on this site about storing variables that are shared between scenes in the storyboard object. I use that quite often, and you may be able to load an image sheet that way as well: [lua]storyboard.imagesheet = [/lua] This allows you to reference your image sheet from any scene, and keeps the variable declaration local.

Hi Greg,

I discourage use of globals in most cases. How about creating them as local in main.lua and then passing them to the scene as parameter(s)? Also, if you’re creating a ton of sprites for the entire game as a whole, it might not be wise to load them all in from the beginning, when only some are needed for a particular scene.

Brent

I create an image sheet per scene, and load them in the createScene method.

Then, they are only loaded if/when the user chooses to use that scene, instead of having a lot of images in memory for the entire life of the program.

Brent/schizoid2k - thanks - take you points re avoiding globals - just focusing on performance/memory usage however for a moment (for understanding purposes):

* I was only talking about create the single imageSheet (not the sprites). Just checking if you understood this.

* If you only have say 20-30 sprite images overall and you have them in a single imageSheet, AND assuming you will want to use some of these in each scene, THEN from a memory perspective have the imageSheet loaded once for the entire duration of the game would be the same as clearing and loading it again in each scene no?  In fact having to open it for each scene you might argue is a little slower.  (again just making the assumption there aren’t hundreds of sprites in the game)

Does this make sense?

Greg, Yes, if you have a small number of images and you plan on using them in multiple scenes, it would probably be best to load everything one time and refer to it. I probably would then either load them in main.lua as a global. There is an article on this site about storing variables that are shared between scenes in the storyboard object. I use that quite often, and you may be able to load an image sheet that way as well: [lua]storyboard.imagesheet = [/lua] This allows you to reference your image sheet from any scene, and keeps the variable declaration local.