SFML community forums
Help => General => Topic started by: jerryd on June 15, 2017, 03:59:19 am
-
SFML forum,
I'm trying to figure out how to use View.
I have read most of the documentation but I don't see
how to load a png file that will be the View. I tried to load
it as I would a Texture but just got a compile error.
sf::View view;
if (!view.loadFromFile("C:/sprites/buildings.png"))
{ cout << " view Loading Error" << endl; system("pause"); }
How do I do this?
jerryd
-
Views can't render an image. If you want to use an image you need to use a texture and render it with a sprite or a vertex array.
And then adjust it to span across the whole view.
-
eXpl0it3r,
Thanks for the reply.
I loaded my background as a Texture and made it a sprite
The window size is 600,600 so I used the command:
sf::View view(sf::Vector2f(600, 600), sf::Vector2f(300, 300));
At one point in my program I used the command:
view.move(100, 0);
but nothing happened.
How do I tie the sprite to the view? Or do I have this all wrong?
-
You need to set the view on the window before you draw the sprite.
I highly recommend you study the official tutorial on views: https://www.sfml-dev.org/tutorials/2.4/graphics-view.php