It doesn't lie, you're trying to access an element in the array that doesn't exist. You need to change your for loop conditions so they don't go out of bounds. They'll start from
sprites[0][0]
then get up to
sprites[0][32]
, there is no element at [0][32] so you get your access violation error.
Now, expanding this to some advice. 1.) Don't use multidimensional arrays, ever. Many people hate them, I hate them, you should hate them.
http://www.cplusplus.com/forum/articles/17108/
2.) In this case you should be fine using
a.) A simple one-dimensional array
sf::Sprite sprites[1024];
b.) A one-dimensional vector
std::vector<sf::Sprite> sprites;
With a vector you can have all sorts of map sizes, as vectors are re-sizable. The only issue I've run into with using a vector is that sometimes if you have a lot them ( like a 1000x1000 tilemap ) that vector can run out of space with its given piece of memory. ( There's a proper word "piece of memory" but it's no longer in my vocabulary ) If you only want around a 1000 sprites, however, then you don't need to worry about that.
As for looping through either of these containers
a.)
1 2 3 4
|
for(int i = 0; i <= numberOfSprites; i++)
{
// do something with your sprite
}
|
b.)
1 2 3 4 5 6 7 8 9
|
for(auto i = sprites.begin(); i != sprites.end(); i++)
{
// auto will make 'i' as type std::vector<sf::Sprite>::iterator
// It's a pain to type that out so auto is handy
// Since 'i' is an iterator, you'll have to use '->' operator like below
i-><some function call here>;
// Or you can de-reference it
*i.<some function call here>
}
|