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

Author Topic: window.SetView() Problem  (Read 2701 times)

0 Members and 1 Guest are viewing this topic.

TheJames

  • Newbie
  • *
  • Posts: 6
    • View Profile
window.SetView() Problem
« on: December 18, 2011, 11:08:21 pm »
Im using SFML 1.6 and whenever I call the set view function the window only displays a blank screen, drawing none of my objects.

Im using this when the window is resized so the view matches the dimensions of the window. My code looks like this:
Code: [Select]

if(events.Type == sf::Event::Resized)
{
    sf::View v(sf::FloatRect(0, 0, events.Size.Width, events.Size.Height));
    window.SetView(v);
}


even when I set the view to the current view the screen is drawn blank:
Code: [Select]

if(events.Type == sf::Event::Resized)
{
    sf::View v = window.GetView();
    window.SetView(v);
}


The only way I have managed to resize my view is by directly referencing the default view (it wont let my directly reference the current view).
Code: [Select]

if(events.Type == sf::Event::Resized)
{
    sf::View &v = window.GetDefaultView();
    v.SetFromRect(sf::FloatRect(0, 0, events.Size.Width, events.Size.Height);
}


Any ideas? Its probably something obvious Im over looking, and I appreciate the help.

Edit:
In my first code example I had declared my view initialization wrong. Regardless I still cant figure out whats wrong.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
window.SetView() Problem
« Reply #1 on: December 18, 2011, 11:54:50 pm »
The window only stores a pointer to the view, so you need to keep it alive as long as it's used.
Laurent Gomila - SFML developer

TheJames

  • Newbie
  • *
  • Posts: 6
    • View Profile
window.SetView() Problem
« Reply #2 on: December 19, 2011, 02:56:08 am »
Makes sense now. Thanks a bunch Laurent