Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

closed as not a real question by msell, bummzack, Byte56, Anko, Josh Petrie Apr 8 '13 at 17:25

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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? – aaaaaaaaaaaa Apr 7 '13 at 4:07
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. – adamk33n3r Apr 7 '13 at 4:52
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. – aaaaaaaaaaaa Apr 7 '13 at 5:21
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? – adamk33n3r Apr 7 '13 at 5:27
up vote 1 down vote accepted

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.