SFML community forums
Help => Graphics => Topic started by: mapPhil on June 10, 2011, 03:30:23 pm
-
So I have an vector that stores multiple asteroids sprites, in its current form it copy's the original asteroid sprite into the vector, could I just point to the original sprite?
this how it is at the moment
imgAsteroid.LoadFromFile("Images/asteroid.png");
sprAsteroid.SetImage(imgAsteroid);
sprAsteroid.SetCenter((imgAsteroid.GetWidth())/2,(imgAsteroid.GetHeight())/2);
std::vector<sf::Sprite> roidStore; //vector to store asteroids
so anytime I add an asteroid to the vector I do
roidStore.push_back(sprAsteroid);
is there anyway I can improve the efficiency of this?
-
It depends how this line of code is used in your code.
A sprite is very cheap to copy so using a pointer instead would just make things much more complicated for nothing.
You should tell us how this vector is used in your code, and what makes you think that it's inefficient (have you used a profiler?).
-
Maybe inefficiency is the wrong word. I just wanted to know because I always like to learn better ways if there are any
But the vector in question is constantly moving and when it collides with bullets the sprite in vector is removed.
I haven't used a profile, do you have any recommendations of one to use?