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

Author Topic: Set Window Position on Creation  (Read 157 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Set Window Position on Creation
« on: July 04, 2020, 05:42:36 am »
There is no option to set the sf::Window position on creation.  Have to create the window, then set its position which causes the window to 'jump'.  Seems to be coded to position in the middle of the screen according to source.  Shouldn't be too difficult to overload the constructor to optionally take in parameters for window location.



  • Hero Member
  • *****
  • Posts: 3001
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: Set Window Position on Creation
« Reply #1 on: July 04, 2020, 08:10:56 pm »
You could create the window at size (1, 1), quickly move it offscreen (e.g. -2000, -2000), resize it to the size you want and then reposition it. This is much less noticeable than moving it onscreen but works even better if the window doesn't need decorations.

One thing I haven't tried is to create the window after setting its position but I would guess that the setting position method affects the actual created window, not the sf::Window object, which would've allowed you to set the position first and that position taken into account when the actual window is created.

With all that said, users tend to accept "imperfect" motion when a window is first set-up and when applications are first started.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter


  • SFML Team
  • Hero Member
  • *****
  • Posts: 9573
    • View Profile
    • development blog
    • Email
Re: Set Window Position on Creation
« Reply #2 on: July 06, 2020, 11:53:31 pm »
The issue here is much more that the window is shown/visible right when the class is instantiated.

This flaw was also picked up in the Window States and Styles discussion here, here, and here.
We don't really want to further uglify the constructor overloads and instead rather provide an option to create windows hidden and let the user decide when it's time to show it.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/