Use two views which each only occupy half of the window. For example, to split the screen in a multiplayer game, you may want to This default behavior is suitable for most situations, but it might need to be changed sometimes. If the view is smaller or larger than the window, everything is scaled to fit in the If the view has the same size as the window, everything is rendered 1:1. Now that you've defined which part of the 2D world is seen in the window, let's define where it is shown. zoom the view relatively to its current size (apply a factor 0.5, so its final size is 600x400) resize the view to show a 1200x800 area (we see a bigger area, so this is a zoom out) Zooming in (or out) a view is done through to resizing it, so the function to use is setSize. rotate the view by 5 degrees relatively to its current orientation (so its final orientation is 25 degrees) To rotate a view, use the setRotation function. move the view by an offset of (100, 100) (so its final position is (300, 300)) That's why the function to change the position of a view is named setCenter, and not Unlike drawable entities, such as sprites or shapes whose positions are defined by their top-left corner (and can be changed to any other point), views areĪlways manipulated by their center - this is simply more convenient. Once your view is defined, you can transform it to make it show a translated/rotated/scaled version of your 2D world.
If you don't want to define the view upon construction or want to modify it later, you can use the equivalent setters: These two definitions are equivalent: Both views will show the same area of the 2D world, a 300x200 rectangle centered on the point (350, 300). create a view with its center and size create a view with the rectangular area of the 2D world to show It can be constructed directly with a definition of the area to view: The class which encapsulates views in SFML is sf::View. They are also the key to creating split screens and mini-maps. To summarize, views are what you need if you want to scroll, rotate or zoom your world. These are the two main features of SFML views. Want to define where/how this area will be shown within the window. Since what is seen in the window is just a small part of the entire 2D world, you need a way to specify which part of the world is shown in the window. Remains unchanged, what changes is just the way it is seen. It is perfectly fine to draw several views of the same world in parallel, or draw the world to a texture rather than to a window. The window is just a view, it shows a specific area What developers might tend to forget is that they define entities in a 2D world, not directly in the window. This is typically the case in RPGs, platform games, and many other genres. In games, it is not uncommon to have levels which are much bigger than the window itself. Controlling the 2D camera with views What is a view?