Jump to content
  • Advertisement
Sign in to follow this  

Texture Bank Structure

This topic is 2787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone.

Can anyone give an advice from their experience on how to structure
the bank of textures. I am making a Breakout remake with lots of levels and different Textures (sprites) I am loading all Texture data when my engine starts.

i have this TextureBank.h file
so i have something like that:

// Texture Bank

#include <qbTextureLoader.h>

#define PADDLES 10
#define BALLS 10
#define FRAMES 10
#define SCREENS 10

static int Paddles[PADDLES];
static int Balls [BALLS ];
static int Frames [FRAMES ];
static int Screens[SCREENS];

// Load Textures
static void loadTextures(){
for(int i=0; i<PADDLES; i++)
Paddles = ImageAdd("Data/sprites/balls/tv1.png");

for(int i=0; i<BALLS; i++)
Balls = ImageAdd("Data/sprites/balls/tv1.png");

for(int i=0; i<FRAMES; i++)
Frames = ImageAdd("Data/Levels/Level_1/frame.png");

for(int i=0; i<SCREENS; i++)
Screens = ImageAdd("Data/Levels/Level_1/screen.png");


then somewhere in the code i just do:

myPaddle.Texture = Paddles[0];

so i just add this .h file where i need my textures, but i have few problems with loading them from static int variables.

Can anyone say if this is a good way at all?

Thanks for your time!

Share this post

Link to post
Share on other sites
A more common approach is to create a system whereby a texture can be requested by name or some other identifier, with a getTexture(filename) method for example. This method returns a texture (or int texture id in your case) and would look at a map of currently loaded textures to see if the requested texture was already loaded, loading it and adding it to the map if not. In your case you might have a map<string,int>

This way, the texture loader doesnt need hardcoded filenames and can load textures on first use. If nescessary you can have a process to preload textures into the map before the level begins

Share this post

Link to post
Share on other sites
WayVirus's approach is good solid approach.

You might want to extend thouh to use a referencing and properties system. So that you declare your texture files in property and only ever call them in code using References.

So you have might have a texture reference called Background and in your level files you specifiy what image file is the background for that level. But code wise the you just make a request to the texture handler class for Background and that handles the loading,caching, to returning of the coresponding texture.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!