Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - BrittleWind

Pages: [1]
1
Graphics / Re: Understanding Views
« on: June 12, 2018, 07:27:11 am »
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.

2
Graphics / Understanding Views
« on: June 11, 2018, 02:57:47 am »
I was going over the documentation for views and watching various video tutorials on the topic and was hoping for some clarification.

My current understanding of views is:

1. When we create a view, we need to specify the center of the view, as well as its dimensions.

2. When we want to change how much of the screen the view takes, we change its viewport.

3. When we want to draw something to the view, we need to set the view on the window, and then draw it.


My question is: How is the view actually determining what goes inside it? I originally, thought that the first step was just creating an "imaginary" rectangle that we later filled in during step 3.

If the contents of the view are being captured in the first step when we specify its center & dimensions, then how does it know what to capture if I haven't drawn anything yet?

I realize that this is a basic question, but I haven't been able to find any resources online to help clear my confusion.

Thank you for your time.

Pages: [1]