Request for general pointers about image loading and memory

Hello all,

first things first. I truly suck at reading the excellent documentation. I'm a self taught dev and haven't done much programming since early 00's. So if my question is plainly answered within the documentation it went over my head.

My Question
In my game a bunch of sprites move past the screen from right to left. I don't spawn more than necessary at a time. They get their image from an image table. Should I
A) load this as a global variable in the main script
or
B) should each sprite load it when spawned?

Which is more efficient memory wise?

At the moment I'm doing B but I'm thinking that A would be better.

Caching is always a balance game, but I think in your case it makes sense to have the image table cached (as a global variable or inside a cache manager singleton) and have the sprite read from it when spawned.

2 Likes