-1
\$\begingroup\$

I in my game I generate some images at runtime depending upon the size of the text that will go over it. Right now I am storing these in a hashmap using a string resembling the text. The question is, is there are better way to do this? Like some sort of ID system?

Also, I would like to expand this to not only be limited to images for when/if I want to include sounds or other resources.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Anything about the system that doesn't work to your satisfaction? To suggest anything better we'd need at least to know exactly why you are storing generated images. What are they used for? Is there a set number of specific images or is there a variable number? How do you clean up images that are no longer needed? \$\endgroup\$ Apr 7, 2013 at 4:07
  • \$\begingroup\$ It just seems like there would be a better way to do it than storing just the string in there. The images are just used as a background for text. I suppose there will be a set number of them once I am done adding new things, but as of now, I will be making more texts. Also, I don't clean up, which is another thing I was wondering about. The way it works now is that it actually loads ALL images used in the entire program at initialization, not only when it needs them which I know is a bad thing especially when I have a lot more things in the future. \$\endgroup\$ Apr 7, 2013 at 4:52
  • \$\begingroup\$ It is not necessarily bad to create them all at load, it is easy, and it avoids some possible issues with slowdowns due to mid-game creation. If it doesn't take too much time don't worry about it. \$\endgroup\$ Apr 7, 2013 at 5:21
  • \$\begingroup\$ Ok thanks for the advice. So you do think that storing them with the key being the string that it is an ok thing to do? \$\endgroup\$ Apr 7, 2013 at 5:27

1 Answer 1

1
\$\begingroup\$

The hashes seem unnecessary, you could store the pointers in a simple array and just give each image an id ranging from 0 to n-1.

While your current system does generate some overhead due to using a hash map, it is probably nothing major. So if it seems to work OK I see little reason to change it.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .