Need suggestion

Started by
2 comments, last by Fredericvo 9 years, 3 months ago

I need a suggestion on how to load multiple images in SDL. All of the games I did before for practice had 1-5 surfaces where I could load an image and move it around. Now lets assume I am making a typing tutor where every letter has its own pretty image. Does it mean I would have to load A B C D..... Z surfaces into the game such as:

SDL_Surface* A = NULL;
SDL_Surface* B= NULL;
SDL_Surface* C = NULL;

A = LoadImage("graphics/A.bmp");

B = LoadImage("graphics/B.bmp");

C = LoadImage("graphics/C.bmp");

....

Z = LoadImage("graphics/Z.bmp");

I know that for the example with alphabet I can just load one image and then cut it up like a sprite but what if I have 100 images that are completely idepandant. Creating 100 surfaces seems wrong. Is there a proper way of doing it?

I was thinking of making a map and loading a proper image path only when I request a specific image key but wouldnt it slow down my program?

Advertisement

I feel like I answered my own question as I was typing this post. mellow.png I see no reason why I cant have only few surfaces but with big tile sheets.

I don't think the number of surfaces probably would matter very much. You could use a numbering system also, and load them by converting an int to the end of the string in a for loop.

Yes, sprite sheets aka texture atlases are used for this so you answered your own question.

This topic is closed to new replies.

Advertisement