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

Author Topic: How to load a png file for View  (Read 1849 times)

0 Members and 1 Guest are viewing this topic.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
How to load a png file for View
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to load a png file for View
« Reply #1 on: June 15, 2017, 06:10:10 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: How to load a png file for View
« Reply #2 on: June 15, 2017, 07:11:50 am »
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?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to load a png file for View
« Reply #3 on: June 15, 2017, 08:37:02 am »
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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything