pygame error: No video mode has been set w/livewires

pygame error: No video mode has been set w/livewires

在我的 pygame 文件中我有:

from livewires import games
import math, random

class Ship(games.Sprite):
    image = games.load_image("images\ship.bmp", transparent = True)

它给出了错误:

pygame error: No video mode has been set

我正在使用 livewires 导入 pygame,这个 post 没有为我的计算机提供正确的答案。

就像post说的,你需要设置

screen = pygame.display.set_mode((800, 600)) # change to the real resolution

你船外的某个地方class(比如你的主要方法)。您的飞船 class 用于在您的游戏中生产物体,而不是创建游戏 window。

如果您将所有 classes 保存在一个文件中,请尝试以下方法:

from pygame.locals import *
from livewires import games
import math, random

def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600)) # change to the real resolution


class Ship(games.Sprite):
    image = games.load_image("images\ship.bmp", transparent = True)

if __name__ == '__main__':
    main()

您需要像这样初始化 livewires 显示:

from livewires import games
import math, random

games.init(screen_width = 640, screen_height = 480, fps = 60)

# game logic here

games.screen.mainloop() # mainloop of the display