How do I create a vector of Sprites using SFML and vector header?
I started the vector like
vector<sf::Sprite> test;
and I’m trying to do a push_back(), but I don’t know what I need to put inside the “()”.
Anyway, my vector will be 41×31, so there is a way t do something like
vector<vector<sf::Sprite> > test (41,vector<sf::Sprite>(31,??))
?
I’m using this to create a tile map, if someone has a better idea, I will appreciate
EDIT:
I still got errors, thats my code
vector<vector<int> > mapc (5,vector<int>(5,1));
sf::Sprite mapa[5][5];
void fmap() {
mapc[0][0] = 1; mapc[0][1] = 1; mapc[0][2] = 1; mapc[0][3] = 1; mapc[0][4] = 1;
mapc[1][0] = 1; mapc[1][1] = 0; mapc[1][2] = 0; mapc[1][3] = 0; mapc[1][4] = 1;
mapc[2][0] = 1; mapc[2][1] = 0; mapc[2][2] = 1; mapc[2][3] = 0; mapc[2][4] = 1;
mapc[3][0] = 1; mapc[3][1] = 0; mapc[3][2] = 0; mapc[3][3] = 0; mapc[3][4] = 1;
mapc[4][0] = 1; mapc[4][1] = 1; mapc[4][2] = 1; mapc[4][3] = 1; mapc[4][4] = 1;
sf::Image w;
w.LoadFromFile("w.png");
sf::Image f;
f.LoadFromFile("f.png");
unsigned int i,j;
for(i=0;i<mapc.size();i++) {
for(j=0;j<mapc[i].size();j++) {
if(mapc[i][j] == 1) { sf::Sprite teste(w); }
else { sf::Sprite teste(f); }
mapa[i][j] = teste;
}
}
// test.push_back(teste);
}
it says that
“‘teste’ was not declared in this scope”
Edit: Actually I lied, if you know the exact size of the map then you can just use
Unless your map is going to be changing its size during runtime you should just create an array on the stack.
Then you’ll want to run through the map one more time to initialize it. If you can’t do that and you need to use a vector then you can do something similar for the vector.
Your map is then accessible as
map[x][y]
in either case.
Hope this helps