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

Author Topic: [Newbie question] Using views  (Read 1719 times)

0 Members and 1 Guest are viewing this topic.

JimJ22

  • Newbie
  • *
  • Posts: 1
    • View Profile
[Newbie question] Using views
« on: July 16, 2014, 01:44:25 pm »
Hi there,

I am trying to understand how the View class works. I am trying to create a simple display with two views, where each view is half of the window size, ie the window is split vertically down the middle. I am using: // view1.setViewport(sf::FloatRect(0, 0, 0.5f, 1)); and view2.setViewport(sf::FloatRect(0.5f, 0, 0.5f, 1)); as shown in the tutorial here: http://sfml-dev.org/tutorials/2.1/graphics-view.php

However I am unsure how to ensure an object is the size of the view. I want to place a rectangle in the bottom half of each view, so essentially I am covering the bottom half of the screen, with one rectangle in each side.

My window size is 300x400. I am making a rectangle of size sf::RectangleShape rectangle(sf::Vector2f(150, 200)); and then setting position with rectangle.setPosition(75, 400);

Is there a way to ensure anything I place inside my view is the same size as the view?

Thanks for any help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [Newbie question] Using views
« Reply #1 on: July 16, 2014, 02:04:10 pm »
You can give your view any size (view.setSize, view.reset), even an arbitrary fixed size if it makes your code easier. It's independant of the viewport, so your views will still take half of the window.

It's important to understand the difference between the size of the view (i.e. which area of the "2D world" it will show) and its viewport (i.e. where and how in the target window the contents view will be displayed).
Laurent Gomila - SFML developer