-
Hello, I'm using SFML 2.0 and am trying to make a simple game using small textures. I want it to display at x2 the original size when first loaded, so immediately after creating the renderwindow I resize and move it.
int windowScale = 2;
sf::RenderWindow window(sf::VideoMode(256, 256), "Resize test");
window.setSize(sf::Vector2u(window.getSize().x*windowScale,window.getSize().x*windowScale));
window.setPosition(window.getPosition()-sf::Vector2i(window.getPosition().x/windowScale,window.getPosition().y)/windowScale);
//...rest of code
Here's the problem, the small screen appears for a brief moment before resizing.
Is there any way to make a window hidden until after it's resized?
I even tried hiding it using setVisible to hide it immediately after creation, resizing, then making it visible again. It didn't work.
-
You probably don't need to hide it like this in the first place.
Create the window at twice the size and then apply an sf::View with the size that you want your game to be.
Example:
int windowScale = 2;
int windowSize = 256;
sf::RenderWindow window(sf::VideoMode(windowSize*windowScale, windowSize*windowScale), "Resize test");
//window resolution is 1060x1060
sf::View gameView;
gameView.setSize(windowSize, windowSize);
window.setView(gameView);
//display resolution is now 256x256
//window is still 1060x1060 pixels large
//...rest of code
-
Thanks, I haven't messed with view much yet. It worked perfect. Except I had to recenter it.
Final working code for a square screen.
int windowScale = 2;
int windowSize = 256;
sf::RenderWindow window(sf::VideoMode(windowSize*windowScale, windowSize*windowScale), "Resize test");
sf::View gameView;
gameView.setSize(windowSize, windowSize);
gameView.setCenter(windowSize/2,windowSize/2);
window.setView(gameView);
//...rest of code