简体   繁体   English

使用PyGame的黑屏

[英]Black Screen using PyGame

I'm currently following a tutorial to use PyGame building a maze. 我目前正在关注一个使用PyGame构建迷宫的教程。 I'm currently working with PyCharm . 我目前正在使用PyCharm I've done indentation reformatting, tried to check every single line for possible indentation problems. 我已经完成了缩进格式,尝试检查每一行是否可能出现缩进问题。 Looked for pygame.update , pygame.display.flip . 寻找pygame.updatepygame.display.flip At least I got the windows up and running but its completely black. 至少我启动并运行了窗户,但窗户完全是黑色的。 I tried to comment certain lines but still got the issue. 我试图评论某些行,但仍然遇到问题。 I'm also working with the latest version of python. 我也在使用最新版本的python。 So here is the code based on the tutorial: 所以这是基于教程的代码:

1) maze.py (Generates the maze when called) https://pastebin.com/9KufTJvM 1) maze.py (在调用时生成迷宫) https://pastebin.com/9KufTJvM

 def setup_maze_window(self):
    # Set up window and layers
    pygame.display.set_caption('MyMaze')
    pygame.mouse.set_visible(0)
    self.background = self.background.convert()
    self.background.fill(WHITE)
    self.m_layer = self.m_layer.convert_alpha()
    self.m_layer.fill(NO_COLOR)
    self.s_layer = self.s_layer.convert_alpha()
    self.s_layer.fill(NO_COLOR)

2) generate_maze.py (Main, calls maze.py) https://pastebin.com/r2TCsb1T 2) generate_maze.py (主要是调用maze.py) https://pastebin.com/r2TCsb1T

The complete code is in the links 完整的代码在链接中

You're forgetting to update the display during the main loop. 您忘记了在主循环中更新显示。

Add a line to generate_maze.py , underneath line 14: 在第14行下面,将一行添加到generate_maze.py

def main():
    current_maze = maze.Maze('create')
    create_dfs(current_maze)
    while 1:
        maze.check_for_exit()
        current_maze.refresh_maze_view() # <== add this line
    return

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM