Game Development Reference
Shapes versus sprites
Probably the most important difference is that a sprite is always rendered as a textured rect-
angle. We can use shapes without textures (just by setting a fill and outline colors), whereas
sprites strictly require a texture to be attached to them. Since sprites are rendered as rect-
angles, we cannot cut parts of a texture like we did with ConvexShape .
Apart from that, the Sprite class has a Sprite::setColor() function, similar to
Shape::setFillColor() . The effect of both the functions is the same as long as the
shape has a texture attached to it as well—the texture gets its color multiplied by the selec-
ted color. The only difference is that if the sprite doesn't have a texture, nothing will be
rendered, whereas the shape is rendered with the specified color.
Furthermore, the sprite dimensions are controlled by its texture. In RectangleShape ,
we set the size of the rectangle that we want to create. With sprite, there is no shape to
define, just the texture. If we want the sprite to appear bigger or smaller, we have to change
the scale of the Sprite object.
Here comes a good question—why would we want to use a sprite instead of a shape? It
seems that the sprite is just a shape with reduced capabilities. This is exactly why we would
want to use it—its simplicity.
Consider the following code:
We can quite clearly see that creating a sprite is a far simpler process. In fact, that is the
main purpose of the Sprite class in SFML—to render a texture on the screen as quickly
and painlessly as possible.
Next, let's see what exactly we can do with a sprite.