How to put limits on resizing a window in pygame

我是研究僧i 提交于 2019-12-04 19:28:47

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!