Sign in to follow this  
Annihilator

Texture Bank Structure

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
#ifndef TEXTURE_BANK
#define 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[i] = ImageAdd("Data/sprites/balls/tv1.png");

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

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

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

#endif




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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this