Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

What is the difference between WindowResized, WindowSizeChanged, and VideoResize events in pygame?

$
0
0

I'd like to scale my sprites when the window gets larger or smaller, I'm not sure which event to watch for in my game loop.

According to the pygame docs:

VIDEORESIZE:

Description: sent when the user adjusts the window dimensions. Attributes: 'size', 'w', and 'h' to give the new size.

The docs call it a "legacy" event and recommend using WINDOWEVENTs.

WINDOWRESIZED:

Description: Window got resized. Attributes: 'x', 'y', and 'window'.

WINDOWSIZECHANGED:

Description: Window changed its size. Attributes: 'x', 'y', and 'window'.

Is there any advantage to using one over the other? Is there any core difference between them?


I made a minimal example to view the events that get sent when I resize the window.

import pygamepygame.init()window = pygame.display.set_mode((1200, 900),pygame.RESIZABLE)pygame.display.set_caption("Minimal Example")clock=pygame.time.Clock()running = Truewhile running:    clock.tick(2) #small fps so not too many events flood in    for event in pygame.event.get():        if event.type==pygame.QUIT: running=False        print(event) #output events that are sent    pygame.display.update()pygame.quit()

Here's an example of some of the output:

<Event(32778-WindowResized {'x': 994, 'y': 661, 'window': None})> <Event(32779-WindowSizeChanged {'x': 994, 'y': 661, 'window': None})> <Event(32769-VideoResize {'size': (994, 661), 'w': 994, 'h': 661})> <Event(32778-WindowResized {'x': 994, 'y': 661, 'window': None})>

All event types give the same width and height values. The 'window' attribute doesn't seem to have any value.

If I resize with my mouse, WindowResized appears twice.If I resize with my keyboard (like + for half-screen), all event types are still sent, and WindowResized only appears once, at the end.

Tutorials I've found online for resizing still all tend to use VIDEORESIZE, and I haven't been able to find articles, discussion threads, or documentation about what the difference is in these event types.Does anyone know the inside code for these, and if it makes any difference using one or the other?


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>