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

Author Topic: Views  (Read 1103 times)

0 Members and 1 Guest are viewing this topic.

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
Views
« on: March 16, 2012, 05:23:13 pm »
Okay, Perhaps my understanding of how views works is flawed, so, i'll explain what i've been doing so far.

Firstly, SFML1.6, it ships with some examples. I looked at the win32 example, since it seems to be doing something similar to what i want to achieve, but it seems to be using things other than just SFML.

What i want to do, is basicly create a single display window. in that window, displayed sub-windows, this is the effect in the win32 demo.

So... I did this:
Code: [Select]
sf::View view2(sf::FloatRect((float)winwidth - minimapwidth, 0, (float)winwidth, (float)minimapheight));

going by the variable names, you can see that this is suposed to be a minimap, in the top right corner of the screen... but thats not what happens, instead it fills the whole screen, and nothing is visible on it except the clear colour.

the drawing routine:
Code: [Select]
App.SetView(view2);
App.Clear(sf::Color(0,0,255));
Sprite2.SetSubRect(sf::IntRect(8, 0, 16, 8));
Sprite2.SetX((minimapwidth-8)*Sprite.GetPosition().x/(currentwidth-8));
Sprite2.SetY((minimapheight-8)*Sprite.GetPosition().y/(currentheight-8));
App.Draw(Sprite2);
App.Display();


all it is really supposed to do is display an 8x8 image on the minimap view in relation to where Sprite, another 8x8 image is on the main view.

I'm doing it wrong, I can tell by how it isn't working, but... what would be the right way to do it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Views
« Reply #1 on: March 16, 2012, 05:56:04 pm »
This is impossible to achieve in SFML 1.6.

A view defines what part of the world will be mapped to the (whole) window. So it's not what you think it is ;)
Laurent Gomila - SFML developer

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
Views
« Reply #2 on: March 16, 2012, 06:11:42 pm »
in that case, i'll have to write my own function that does that part for me.

for now (since i'm still just experimenting with stuff) I've set view2 to the same size as the main view, and come up with this:
Code: [Select]
App.SetView(view2);
App.Draw(sf::Shape::Rectangle((float)winwidth - minimapwidth, 0, (float)winwidth, (float)minimapheight, sf::Color(0,0,255)));
Sprite2.SetSubRect(sf::IntRect(8, 0, 16, 8));
Sprite2.SetX((winwidth - minimapwidth)+((minimapwidth-8)*Sprite.GetPosition().x/(currentwidth-8)));
Sprite2.SetY((minimapheight-8)*Sprite.GetPosition().y/(currentheight-8));
App.Draw(Sprite2);
App.Display();


Main change is replacing the App.Clear() with App.Draw(Rectangle).

Am i on the right track now?

 

anything