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

Author Topic: Tryng to create two views  (Read 2065 times)

0 Members and 1 Guest are viewing this topic.

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Tryng to create two views
« on: February 03, 2017, 01:24:02 am »
I am again struggling. I am trying to create two views. The view is suppose to be menu and the other view the playing surface. Both views are covering the same space. I am currently trying to make views shift to different areas.

Here is my main rendering code;

_render.setView(_render.getDefaultView());
               
               
                _render.setView(_menu.menuView(sf::FloatRect(0, 0, 0.5, 0.5)));
                texture.draw(_menu.newBoard());
                sf::View current = texture.getView();
                _render.setView(_render.getDefaultView());

               
                _play.viewport(sf::FloatRect(0, 0.5, 1, 1));
                _render.setView(_play._view);
                texture.draw(_play.draw());
                sf::View currentview = texture.getView();
               
               
                //Return drawing back to main window
                _render.setView(_render.getDefaultView());
                texture.display();
                _render.clear();


And here is my viewport function:

_view.reset(sf::FloatRect(200, 200, 300, 200));
       
        _view.setCenter(20, 20);
        _view.setSize(800,800);
       
       
        _view.setViewport(dimensions);
       
       
        return _view;

Thanks.
« Last Edit: February 03, 2017, 01:46:32 am by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tryng to create two views
« Reply #1 on: February 03, 2017, 01:47:22 am »
You're welcome! ;D

So what's the issue?

PS: Make sure to use [code=cpp][/code] tags :)
« Last Edit: February 03, 2017, 01:49:11 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Tryng to create two views
« Reply #2 on: February 03, 2017, 02:02:35 am »
I have two views the first covers the second view, blotting out the second view. I need these two  views to be shown at different sections on the screen. Thanks

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Tryng to create two views
« Reply #3 on: February 03, 2017, 03:42:36 am »
One of those views you are making is going to cover the entire screen. They use a ratio of 0-1, so 1 is the entire width/height, depending on which parameter.

Here's what I usually do to create a view somewhere on the screen
sf::FloatRect SomeArea =
{
  800, //Left
  200, //Top
  350, //Width
  210  //Height
};
sf::View View;
sf::FloatRect Region =
{
  SomeArea.left / WindowSize.x, //The ratio of how far from the right I want my view to start compared to how wide the screen is
  SomeArea.top / WindowSize.y,//The ratio of how far from the top I want my view to start
  SomeArea.Width / WindowSize.x, //The ratio of how wide I want the view to be to how wide the screen is
  SomeArea.height / WindowSize.y  //The ratio of how tall I want the view to be to how tall the screen is
};
View.setViewport(Region);
/*Use view however you wanted*/
I use views for clipping usually, but also for minimaps, etc.

hthornto

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Tryng to create two views
« Reply #4 on: February 03, 2017, 04:32:16 am »
Thanks, You formula is great idea. I was able to get it to work.

 

anything