Hashtg wrote: |
---|
Quick question, what are the implications of using a 'vector <Sprite>' instead of a 'vector <Sprite*> |
vector<Sprite> stores the actual sprite data in the vector.
vector<Sprite*> only stores a pointer to the sprite in the vector.
Advantages to vector<Sprite>:
- Accessing individual sprites is faster*
- Memory is managed automatically for you (no need to delete)
Advantages to vector<Sprite*>:
- Allows you to create polymorphic sprites (if you are deriving classes from sf::Sprite)
- Resizing the vector / removing elements from the vector is faster*
* take "faster" with a grain of salt, because the difference will be miniscule.
So unless you're deriving your own classes from sf::Sprite and want them to behave polymorphically, there's little reason to use pointers here -- since pointers just make you have to manage the memory yourself (more prone to errors/mistakes/leaks).
m4ster r0shi wrote: |
---|
you may have many bullets (objects) in your game, but
you'll want to have only one in_game_bullet_image (sprite) which will be created
using an image file (raw resource). |
SFML uses different terminology.
The actual image is an sf::Image. That is a resource that should not be frequently copied/reconstructed.
An sf::Sprite is just like a rectangle with some attributes for color/rotation/position/etc. You typically use one sf::Sprite for each bullet, but all those sprites share the same sf::Image.