鱼C论坛

 找回密码
 立即注册
查看: 1601|回复: 0

pygame 问题 ------已解决

[复制链接]
发表于 2018-3-23 12:40:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 cats_miao 于 2018-3-24 09:04 编辑

还有一个调用的py文件
在这里 http://bbs.fishc.com/thread-107447-1-1.html

可以复制这2个文件代码,运行试.
我的不行...希望大神们能解决一下,谢谢

import time
import pygame
from plane_sprites import *


class PlaneGame(object):
    """飞机大战主游戏"""
    def __init__(self):
        print("游戏初始化")

        # 1.创建游戏的窗口
        self.screen = pygame.display.set_mode(SCREEN_RECT.size)
        # 2.创建游戏的时钟
        self.clock = pygame.time.Clock()
        # 3.调用私有方法,精灵和精灵组的创建
        self.__create_sprites()


    def __create_sprites(self):
        pass


    def start_game(self):
        pygame.init()
        print("游戏开始....")

        while True:
            # 1.设置刷新帧率
            self.clock.tick(60)
            # 2.事件监听
            self.__event_handler()
            # 3.碰撞检测
            self.__check_collide()
            # 4.更新/绘制精灵组
            self.__update_sprites()
            # 5.更新显示
            pygame.display.update()



    def __event_handler(self):

        for event in pygame.event.get():

            if event.type == pygame.quit():
                PlaneGame.__game_over()

    def __check_collide(self):
        pass

    def __update_sprites(self):
        pass

    @staticmethod
    def __game_over():
        print("游戏结束")
        pygame.quit()
        exit()

if __name__ == '__main__':
    # 创建游戏对象
    game = PlaneGame()

    # 启动游戏
    game.start_game()





运行主文件 plane_main.py 后

出现如下问题:
游戏初始化
游戏开始....
Traceback (most recent call last):
  File "/home/miao/planeGame/p_game_1/plane_main.py", line 65, in <module>
    game.start_game()
  File "/home/miao/planeGame/p_game_1/plane_main.py", line 37, in start_game
    pygame.display.update()
pygame.error: video system not initialized

Process finished with exit code 1


请各位大神帮忙解决一下,万分感谢!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-9 16:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表