SFML community forums
Help => Graphics => Topic started by: Aaron on July 23, 2012, 02:39:06 am
-
Suppose I want to draw an image twice. It could be for two entities with different positions but the same image, or it could be for tiles in a tilemap.
Is it better to have a sprite for each instance of the image I want to draw? Or can I get away with having only a single sprite for the image, where I'd change the sprite's position whenever I want to draw its image?
-
For a tilemap the best way is to use a sf::VertexArray (there are a few examples floating around in the forum).
If you want to draw multiple entities of the same texture, it only depends on your game engine design, what fits your needs most.
In all cases you'll have to make sure that you don't load the same textures twice but share them under your sprites.
The reason it's okay to have many sprites is that the sf::Sprite class is light weightened thus it doesn't matter so much (if we don't talk about tens of thousands).
If you got a more specific example we might have a more specific answer. ;)
-
It could be for two entities with different positions but the same image
Use a sprite for each entitie.
it could be for tiles in a tilemap.
Use a sprite for each tile. So you will can scale individual tiles etc.
-
it could be for tiles in a tilemap.
Use a sprite for each tile. So you will can scale individual tiles etc.
No defenetly don't do that. For a few thousand or even hundred tiles this can lead to big performance issues. Also the vertex array is an optimized datastructure for GPU and will thus work way better.
Why would you need to scale individual tiles?
-
I dunno. It may be useful (or not).