在我的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没有为我的计算机提供正确的答案。
答案 0 :(得分:0)
就像那篇帖子所说,你需要设置
screen = pygame.display.set_mode((800, 600)) # change to the real resolution
您的船级以外的某个地方(就像您的主要方法一样)。您的船级用于在游戏中生成对象,而不是创建游戏窗口。
如果要将所有课程保存在一个文件中,请尝试以下操作:
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()
答案 1 :(得分:0)
您需要初始化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