Game Development Reference
In-Depth Information
How does SFML implement a camera?
If we want to modify the default camera which comes with each
sf::Window
instance,
we have to tackle the
sf::View
class.
The
View
class behaves exactly like a typical camera—limiting what the player can see in
the world by a set of parameters. This is how we create and use
View
:
The constructor of the
View
class takes a single
FloatRect
parameter, which sets the
desired view area of the world. If we have a bigger view area, its contents are scaled down
to fit in the window, and vice versa. In this example, the area matches the window size, so
it does not change how objects are rendered.
Finally, when we have everything in
View
configured, we need to tell the window to use it
by calling
RenderWindow::setView()
. This copies over the view in the
Render-
Window
object, so we don't need to keep the original view alive, as we do with resources
such as
Texture
.
Now, let's see what the
View
class can actually do.