lordmauve / pgzero

A zero-boilerplate games programming framework for Python 3, based on Pygame.
https://pygame-zero.readthedocs.io/
GNU Lesser General Public License v3.0
536 stars 189 forks source link

Window always starts partially off-screen #247

Closed arganoid closed 3 years ago

arganoid commented 3 years ago

Regardless of window size, the window always opens with its top left corner almost (but not quite) in the centre of the screen. On my 1080p screen this means any window taller than about 530px or wider than about 1000px goes off the edge of the screen. This issue does not occur with pygame games, which are always centred.

pygame 2.0.1 (SDL 2.0.14, Python 3.7.5) pgzero 1.2.1 Windows 10 image

lordmauve commented 3 years ago

Ah. This will be because we create a small window first and then resize it. The small window is needed so that we can load sprites. A dirty fix would be to make that window large instead, which would move the window towards the top-left.

We could try positioning the window ourselves when we resize.

Ultimately we may need to get rid of the small startup window phase. It causes many problems.

dogwynn commented 3 years ago

In addition to the issue of the window starting partially off-screen, if there is not an update function defined, then the portion of the window off-screen is not rendered on some systems. Thus, when you move the window so that it is fully visible, that off-screen portion is then black.

lordmauve commented 3 years ago

@dogwynn I have a hunch that's a different bug: we should be handling Pygame's VIDEOEXPOSE event and triggering a redraw. Can you open a new issue or shall I do it?

kvnsmth commented 3 years ago

i didn't have any luck figuring out how to reposition the window, but here is a quick hack i came up with while trying to fix this for my son. i'm not a python programmer so there is probably a better way. :D

# --- window hack
import pygame

WIDTH = 1260
HEIGHT = 768

pygame.display.set_mode((WIDTH, HEIGHT))

# --- start pgzero code
import pgzrun

pgzrun.go()

@lordmauve thanks so much for making this. my son is having a blast. it is so nice for him to not have all the boiler plate of using pygame directly.

arganoid commented 3 years ago

The workaround does seem to work for me, but are there any potential problems with it on older versions or other OSes? I am writing a book about making games with Pygame Zero, so I need to decide whether to include the workaround in the code for the example games. Is there any prospect of the underlying issue being fixed in the next few months?

lordmauve commented 3 years ago

Fixed in bf48fc9.

Ultimately we may need to get rid of the small startup window phase. It causes many problems.

Dropping the .convert_alpha() calls that this is used for is prohibitive for performance; these provide a 5x speed-up.

The fix I implemented is to use the temporary window but destroy it afterwards. Then the real game window is centred on the screen.