-
Hello, I am trying to display a full screen image using Views. This is my code:
sf::RenderWindow mWindow(sf::VideoMode(800,600), "Prueba Animaciones");
// Cargo la imagen y muestro un pedazo
sf::Texture mBGTexture;
sf::Sprite mBGSprite;
if(!mBGTexture.loadFromFile("bg_big.png")) return EXIT_FAILURE;
mBGSprite.setTexture(mBGTexture);
imageWidth = mBGTexture.getSize().x;
imageHeight = mBGTexture.getSize().y;
sf::CircleShape mBall;
mBall.setRadius(10.0);
mBall.setFillColor(sf::Color::White);
sf::View miniMap;
miniMap.setSize(imageWidth, imageHeight);
miniMap.setViewport(sf::FloatRect(0, 0, 1, 1));
mWindow.setFramerateLimit(60);
while(mWindow.isOpen()){
mWindow.clear();
mWindow.setView(miniMap);
mWindow.draw(mBGSprite);
mWindow.draw(mBall);
mWindow.display();
}
The result is this: http://db.tt/14sjmZol. As you can see it is not using the full screen and my image is cutted on right (this is the original image: http://db.tt/5Q6D3uN5). Why this happens? Isn't it suppose to show me the full image on the window ?
-
Hi,
First I'm wondering why you type miniMap.setViewport(sf::FloatRect(0, 0, 1, 1));
since the default behavior of a View is taking all the window. Plus, calling mWindow.setView(miniMap);
in the main loop is not essential, you can do it once.
My first reflex would have been to call sf::View::reset()
or directly use the constructor
sf::View miniMap(0, 0, imageWidth, imageHeight);
Hope this helps you.
-
What gostron said + the view is in the wrong position as far as I can see.
Add this after you create the view:
miniMap.setCenter(imageWidth/2, imageHeight/2);
or even better intialize the view like this:
sf::View miniMap(mBGTexture.getSize()/2,mBGTexture.getSize())
-
I feel stupid :P The problem was the position thank you guys!!