1
Graphics / Declaring array of sprites with identical texture.
« on: November 27, 2016, 11:39:52 pm »
Hey all,
Pretty new to SFML and C++ in general. I'm wondering how you guys typically declare an array of sf::Sprites. I'm currently working on an Asteroids clone and I'm working on how best to implement a bullet system. I'm currently trying something like below:
My issue is that when I go to iterate through and draw all of the active bullets, the last bullet to fire is the only one that gets drawn. I have a feeling it's related to how I'm creating the sprites and assigning them to my array. Is it possible that because I'm creating all of my sprites with the same texture that it's messing up the drawing?
Also, is this the correct way to approach an array of objects like this? Would like to hear if there's a better/more efficient way of handling arrays in C++. Thanks!
Pretty new to SFML and C++ in general. I'm wondering how you guys typically declare an array of sf::Sprites. I'm currently working on an Asteroids clone and I'm working on how best to implement a bullet system. I'm currently trying something like below:
sf::Texture * bulletTexture = new sf::Texture;
bulletTexture->loadFromFile(pathToBulletPNG);
sf::Sprite * sprites[100];
for (int i = 0; i < 100; ++i)
{
sprites[i] = new sf::Sprite(*bulletTexture);
}
bulletTexture->loadFromFile(pathToBulletPNG);
sf::Sprite * sprites[100];
for (int i = 0; i < 100; ++i)
{
sprites[i] = new sf::Sprite(*bulletTexture);
}
My issue is that when I go to iterate through and draw all of the active bullets, the last bullet to fire is the only one that gets drawn. I have a feeling it's related to how I'm creating the sprites and assigning them to my array. Is it possible that because I'm creating all of my sprites with the same texture that it's messing up the drawing?
Also, is this the correct way to approach an array of objects like this? Would like to hear if there's a better/more efficient way of handling arrays in C++. Thanks!