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

Author Topic: Help with sf::View  (Read 1633 times)

0 Members and 1 Guest are viewing this topic.

Symphonym

  • Newbie
  • *
  • Posts: 32
    • View Profile
Help with sf::View
« on: August 12, 2012, 02:35:33 pm »
Hi

So I'm currently making a game that uses pixelgraphics for most sprites and whatnot, having tiny images that I scale up in SFML. The thing is, to scale all my sprites I run them through a draw method which simply does "setScale()" using the constant float containing the scale factor. However, when I'm rendering many sprites, such as a tile grid, it takes a moment for the sprites to scale, which gives an ugly looking 1-2 seconds when loading the tile grid. This could ofcourse be because the tile rendering is very uneffective at the moment, as I render every tile and not only those who are visible.

So I was thinking if there was a better way scaling my sprites, using a "sf::View" instead. But I can't seem to understand how it works properly. How much would a times 5 scaling be using the "view.zoom". And as the zoom function zooms to the center, all my sprites are getting placed outside the window, or atleast they're not visible.

So any tips on how I should be scaling pretty much all my sprites to a constant scale effectively?

EDIT: I'm using SFML 2.0
« Last Edit: August 12, 2012, 02:50:09 pm by Symphonym »

7krs

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Help with sf::View
« Reply #1 on: August 19, 2012, 01:44:07 pm »
Well scaling up does expel some sprites from the rendering area, even if you use your method of iterating through an array/vector of sprites whilst setting the scale for each of them. If the previous sentence is not true, then I don't understand what you really mean.  Also, not all of your sprites will be placed outside your window if you zoom (moderately). Note that you can set the center of your view using sf::View::setCenter(sf::Vector2f(x,y)). Then set the view to the RenderTexture/Window using ::setView(sf::View).

Hope that helps.
« Last Edit: August 19, 2012, 01:49:44 pm by 7krs »

TheVirtualDragon

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Control + Alt + Delete!
Re: Help with sf::View
« Reply #2 on: August 20, 2012, 08:53:37 pm »
When you create a view, you have to make a sf::FloatRect, which is the area of the view. So, for example, if you are currently scaling your sprites by 50, you could do this instead:

Code: [Select]
sf::View exampleView ( sf::FloatRect(0, 0, windowWidth / 50, windowHeight / 50) );

And then make the window use the view with this function:

Code: [Select]
sf::RenderWindow::SetView(&sf::View);

 

anything