Menu

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.

Show posts Menu

Topics - tim_the_cat

#1
Help requests / view / camera
26 August 2022, 15:59:17
hello, I will say right away, English is not my native language, I apologize in advance for the mistakes...
I'm new to tgui, trying to find a way to make a camera by means of tgui. I tried to do it using sf::View, it didn't work, the center of myView changes, but the widgets do not move relative to the center of the screen, probably I don't understand something...

I've been writing because I've spent too much time looking for a solution, and the camera is a necessary aspect of the program I'm building.

please tell me how to implement the camera :<


failed attempt:
while (not end) {
                    window.clear();
                    window.setView(view);
                    sf::Event event;
                    while (window.pollEvent(event)) {
                        gui.handleEvent(event);
                        switch (event.type) {
                        case sf::Event::Closed:
                            groupSwitching(0);// exit
                            break;
                        case sf::Event::KeyPressed:
                            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { // my stupid attempt to make a camera
                                view.setCenter(view.getCenter().x + 10, view.getCenter().y);
                            }
                            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                                view.setCenter(view.getCenter().x - 10, view.getCenter().y);
                            }

                            std::cout << view.getCenter().x << " " << view.getCenter().y << std::endl;
                            break;
                        case sf::Event::MouseWheelScrolled:
                            if (event.mouseWheelScroll.delta < 0)
                                view.zoom(1.1f);
                            else if (event.mouseWheelScroll.delta > 0)
                                view.zoom(0.9f);

                            std::cout << view.getCenter().x << " " << view.getCenter().y << std::endl;
                            break;
                        }
                    }
                   
                    gui.draw();
                    window.display();
}