所以我正在用Pygame开发一个游戏,并试图抽象出很多代码。但在这个过程中,我得到一些奇怪的错误。也就是说,当我跑的时候主.py,我得到这个线索:
>>>
initializing pygame...
initalizing screen...
initializing background...
<Surface(Dead Display)> #Here I print out the background instance
Traceback (most recent call last):
File "C:\Users\Ceasar\Desktop\pytanks\main.py", line 19, in <module>
background = Background(screen, BG_COLOR)
File "C:\Users\Ceasar\Desktop\pytanks\background.py", line 8, in __init__
self.fill(color)
error: display Surface quit
我想这和我使用main中的上下文来管理屏幕有关。在
^{pr2}$有什么想法导致这里的错误?在
我也在尝试子类化游戏。表面因为我想给它添加属性。下面就可以实现这一点。我希望它能帮助未来的人们。在
在pygame.display.set_模式必须调用(),因为它初始化所有游戏机视频东西。看来pygame.display最终被吸引到屏幕上的表面。因此,我们需要将我们创建的任何曲面blit为pygame.display.set_模式()(这只是另一个游戏。表面对象)。在
从技术上讲,这不是我的答案,但问题是Surface不能用Python的super进行扩展。相反,它应该被称为Python老式类,如下所示:
来源:http://archives.seul.org/pygame/users/Jul-2009/msg00211.html
相关问题 更多 >
编程相关推荐