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

Author Topic: Make window hidden when created  (Read 3107 times)

0 Members and 1 Guest are viewing this topic.

zacintosh

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Make window hidden when created
« on: December 18, 2012, 06:16:05 am »
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.
« Last Edit: December 18, 2012, 06:17:42 am by zacintosh »

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Make window hidden when created
« Reply #1 on: December 18, 2012, 06:21:25 am »
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
« Last Edit: December 18, 2012, 06:35:26 am by thePyro_13 »

zacintosh

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Make window hidden when created
« Reply #2 on: December 18, 2012, 06:41:32 am »
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
 
« Last Edit: December 18, 2012, 06:48:05 am by zacintosh »

 

anything