首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >游戏错误:未设置视频模式

游戏错误:未设置视频模式
EN

Stack Overflow用户
提问于 2015-02-23 20:13:39
回答 2查看 763关注 0票数 0

在我的玩偶档案里有:

代码语言:javascript
复制
from livewires import games
import math, random

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

它给出了错误:

代码语言:javascript
复制
pygame error: No video mode has been set

我使用livewires来导入游戏,而这个post没有给我的计算机一个正确的答案。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-23 20:38:40

您需要初始化livewires显示,如下所示:

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2015-02-23 20:22:30

就像那个帖子说的,你需要设置

代码语言:javascript
复制
screen = pygame.display.set_mode((800, 600)) # change to the real resolution

在您的ship类之外的某个地方(比如您的主要方法)。您的ship类用于在游戏中生成对象,而不是创建游戏窗口。

如果要将所有类保存在一个文件中,请尝试如下所示:

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28682570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档