【问题标题】:pygame crashes when i try to resize window当我尝试调整窗口大小时,pygame 崩溃
【发布时间】:2013-09-16 22:38:03
【问题描述】:

这个确切的问题是去年四月在这个论坛上提出的。但是,唯一的答案是:“您的脚本在我的系统上运行,检查并确保您拥有适用于您的 python 版本的 pygame 模块。”所以我先检查了这个,然后检查了。 (我有 Python 2.7 和 Python 2.7 的 Pygame 版本 1.9.1。)

所以不是这样,但是下面的代码会产生与其他人报告的相同的错误:

This application has requested the runtime to terminate it in an unusual way. Please contact the application's support team for more info.

我希望最初的发帖人说他们做了什么来修复它,因为我很难过。请注意,我在尝试运行它的机器上没有管理员权限。会不会是这个问题?

脚本如下。 (这直接取自Beginning Game Development with Python and Pygame一书。)它会一直运行到您尝试调整窗口大小的那一刻。

background_image_filename = 'sushiplate.jpg'

import pygame
from pygame.locals import *
from sys import exit

SCREEN_SIZE = (640, 480)

pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE, 32)

background = pygame.image.load(background_image_filename).convert()

while True:

    event = pygame.event.wait()
    if event.type == QUIT:
        exit()
    if event.type == VIDEORESIZE:
        SCREEN_SIZE = event.size
        screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE, 32)
        pygame.display.set_caption("Window resized to "+str(event.size))

    screen_width, screen_height = SCREEN_SIZE
    for y in range(0, screen_height, background.get_height()):
        for x in range(0, screen_width, background.get_width()):
            screen.blit(background, (x, y))

    pygame.display.update()

【问题讨论】:

  • 可能有用的一件事是问另一个问题的 OP,谁知道呢,他可能回应。

标签: python python-2.7 pygame


【解决方案1】:

警告,您正在为每个触发的事件绘制。你反而想要:

while True:

    for event in pygame.event.get():

        if event.type == QUIT:
            exit()
        elif event.type == VIDEORESIZE:
            # ...
        elif event.type == KEYDOWN:
            # ...
    # draw.
    pygame.display.update()

接下来的代码没有意义:你想做什么?

screen_width, screen_height = SCREEN_SIZE
for y in range(0, screen_height, background.get_height()):
    for x in range(0, screen_width, background.get_width()):
        screen.blit(background, (x, y))

pygame.display.update()

【讨论】:

  • 他正在用平铺背景覆盖屏幕
  • 但它是多余的 blitting,多次绘制相同的像素。我认为他正在尝试使用常规的平铺 blit。
【解决方案2】:

尝试在调整大小模式设置中移除颜色深度:

screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE)

我得到了和你一样的错误,留下了颜色深度,当我删除它时它就消失了。我不知道它为什么会失败,但是根本没有关于 VIDEORESIZE 事件的官方文档,除了 Event 对象的大小、w 和 h 字段设置为某个值。 (现在检查这个很困难,因为 pygame.org 目前已关闭,据报道是由于服务器 RAID 错误,但您可以谷歌获取信息,并查看缓存页面。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    相关资源
    最近更新 更多