Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Removing elements from vector

Name: Anonymous 2011-12-05 9:25

Hi there /prog/

I have a vector that looks like:
<code>
std::vector<Bullet> bullets;
</code>

My bullet struct contains the bullet ID, pixel data, and position.
I set the ID to bullets.size(); on creation.

Whenever a bullet is outside of the camera view, I call: (obviously inside of a loop)
<code>
bullets.erase(bullets.begin() + bullets[bi].ID);
</code>

This works pretty well, unless I spam bullets on the screen.  After a few bullets leave the screen, they all disappear.

What would be the best way to handle cleaning up my bullets?

Name: Anonymous 2011-12-05 9:51

>>3
What would be a better method for handling my bullet clean up?  Initially I assumed you meant something like this:

bullets.erase(bullets.end() - bullets[bi].ID);


but obviously that's essentially the same thing.

I was thinking about using an std::map<int, Bullet> object, and keep adding one to the ID each time instead of setting the ID to bullets.size();

Would that be an efficient method?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List