How to put limits on resizing a window in pygame

前端 未结 1 1008
野性不改
野性不改 2020-12-18 11:53

I have a window in pygame set up like this: screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT),pygame.RESIZABLE)

As you can see, it is resizab

相关标签:
1条回答
  • 2020-12-18 12:54

    You can use the pygame.VIDEORESIZE event to check the new windows size on a resize. What you do is on the event, you check the new windows size values, correct them according to your limits and then recreate the screen object with those values.

    Here is a basic script:

    import pygame
    from pygame.locals import *
    pygame.init()
    screen = pygame.display.set_mode((640,480), HWSURFACE|DOUBLEBUF|RESIZABLE)
    while True:
        pygame.event.pump()
        event = pygame.event.wait()
        if event.type == QUIT: pygame.display.quit()
        else if event.type == VIDEORESIZE:
            width, height = event.size
            if width < 600:
                width = 600
            if height < 400:
                height = 400
            screen = pygame.display.set_mode((width,height), HWSURFACE|DOUBLEBUF|RESIZABLE)
    

    EDIT: Depending on how your game graphics are drawn, you may want to resize them according to the windows resize (haven't tested that, just going after this example: http://www.pygame.org/wiki/WindowResizing)

    0 讨论(0)
提交回复
热议问题