Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can I improve the efficiency of my vector for sprites?  (Read 1840 times)

0 Members and 1 Guest are viewing this topic.

mapPhil

  • Newbie
  • *
  • Posts: 11
    • View Profile
Can I improve the efficiency of my vector for sprites?
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can I improve the efficiency of my vector for sprites?
« Reply #1 on: June 10, 2011, 03:43:51 pm »
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?).
Laurent Gomila - SFML developer

mapPhil

  • Newbie
  • *
  • Posts: 11
    • View Profile
Can I improve the efficiency of my vector for sprites?
« Reply #2 on: June 10, 2011, 04:09:45 pm »
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?

 

anything