I've got a game that has 3 basic sprites, at the moment I'm loading 8 images into each sprite for animating. Each character class has a sprite object. if I've got 10 characters on screen at once then that's 80 images loaded in to memory. Can I make a central sprite class that only holds 8 images for each of the 3 sprites, then get the character objects to request the relevant images from the central sprite class, thereby massively reducing the memory required for the images?
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
|
|
You can and you probably should. I believe that in Java (as in C#) objects are going to be passed by reference, so you should get this behavior by default without doing any extra work. Code like this:
Should give you three A quick search shows that I stand corrected. Java is in fact pass-by-value; however, since java has "pointers" the result in the code above should remain the same. Java passes the pointer to the sprite by value; but they will all still "reference" the same sprite. |
|||||
|