For some reason my head is not on strait and I cannot work this out.
The code below loads the bitmap I do know that and then when adding it to the vector it just crashes. I'm trying to write this so that I can use it over and over again in my project but without even getting the rest added I need to get this fixed.
Any help would be very appreciated.
Think about the size of the vector for a second. If you use 'resize(10)' then what is the greatest index you can access of the vector? It's 9, or in your case 'size() - 1'. You need to resize the vector to 'id + 1' so you can access vector[id].
I tried texture.resize( id+1 ); and even tried texture.resize( id+100 );
I still get it crashing
This is why it is confusing me.
Append: Fixed it. It was.
And should have been.
Try this :
if ( id >= (signed)texture.size() ) { texture.resize( id + 1); }
Note the >= sign instead of >.
, yea, Thanks. I just realized that though
Maybe you would like a std::map<std::string , ALLEGRO_BITMAP*> better?
Then you could lookup textures by their name. Just an idea, it may not suit you.
This is my kind of idea.
This is to make it quicker for making games. There will be a lot more functions but I'm working on the main ones at the moment.
I could use std::map<int , ALLEGRO_BITMAP*> but either way works
All those ids make me dizzy.
How do you keep track of which id you want to use? I suppose you store it in a class?
To keep track of it would be as you said different classes or you can name the numbers using...
#define PLAYER_TEXTURE = 0
#define ENEMY_TEXTURE = 1
...
This is how DarkGDK works and I like the way it's so basic. Obviously the basic stuff I need to code the more complex stuff first but then when I make games I can just use my own library instead
Something suspicious about the sound API: does id refer to a sound resource, or one instance of a sound being played ? ie: If two long "character babble" sounds are playing at the same time, how does StopSound know which one it should cut ?
Same with SetSoundPan if it's for stereo and SetSoundGain for volume.
It will be stored in a struct with the relevant ID. Then to stop it the instance id is taken from the struct.
I shall be adding more commands than just those. That's just a mockup idea not the actual functions.