Sorry for my misleading question. My question is just how I tell the view what it will contain. On the tutorial, the section on this shows that you only have to set the center & position of the view.
However, when I tried doing something similar, I wasn't able to understand my result.
#include <SFML/Graphics.hpp>
using namespace sf; //I know this is bad :(
int main() {
RenderWindow w(VideoMode(800, 600), "View Test");
Font f;
View v;
if (!f.loadFromFile("Roboto-bold.ttf"))
return -1;
Text t;
t.setString("Hello!");
t.setFont(f);
t.setFillColor(Color::White);
t.setCharacterSize(100);
Vector2f pos = t.getPosition();
FloatRect size = t.getGlobalBounds();
v.setCenter(Vector2f(pos.x / 2.f, pos.y / 2.f));
v.setSize(Vector2f(size.width, size.height));
while (w.isOpen()) {
Event e;
while (w.pollEvent(e)) {
switch (e.type) {
case Event::Closed:
w.close();
}
}
w.setView(v);
w.clear();
w.draw(t);
w.display();
}
}
With the following output:
My goal here was to create a view that contains the text, but I am assuming that I "captured" the incorrect part based on the output.
I understand that the view appears blown-up because by default the view takes the entire screen.
To summarize my question: When do we actually control what the view contains?
Hypothetically, if we have multiple things we want to display (like a background, healthbar, score, menu, etc..) at the same time, is it considered "good" to assign a view to each element, or is there a better way to do this?
I realize this is a simple question, but I've looked up a lot of different resources online and am still very confused, so thank you for your time.