pygame.init()到底是什么?
我曾经读过/看到的每一个pygame教程都说在您考虑做其他任何事情之前,都会将“ pygame.init()”挤入您的代码中。显然,它初始化了Pygame模块之类的东西,这似乎很重要。
直到我想从我的代码中删除“ pygame.init()”行,只是为了看看会发生什么。瞧,我的游戏工作完全相同。
我登上了网络,再次,我被告知“ pygame.init()”是必要的。但是不,显然不是,因为我只是从我的代码中取出它,这很好。
因此,不用说,我很困惑。如果有人解释:
a)pygame.init()b)的功能
是否在Pygame程序中需要。 如果是这样,那我的游戏为什么要工作 如果不是,那么什么时候需要?
c)您认为我应该知道的其他任何事情
Every pygame tutorial I have ever read/seen have said to squeeze 'pygame.init()' into your code before you think about doing anything else. Apparently, it initializes pygame modules or something, which seems pretty important.
This was until I thought to remove the 'pygame.init()' line from my code, just to see what would happen. Lo and behold, my game works exactly the same.
I took to the web and once again, every where I went, I was told 'pygame.init()' is necessary. But no, it is clearly not, as I just took it out of my code which works just fine.
So, needless to say, I am pretty confused. I would really appreciate it if someone explained:
a) the function of pygame.init()
b) whether or not it is required in a pygame program.
if it is, then why did my game work
and if it is not, then when is it needed?
c) any other things you think I should know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 www.pygame.org
此外,在这里,我们可以看到一开始就可以安全地进行:
最后,我认为为什么始终在一开始总是使用它的主要原因:
因此,主要的结论是
pygame.init()
安全地初始初始化了所有导入的pygame模块,无论模块是否真的需要初始化;但是,由于它适用于那些这样做的人,因此可以节省单独初始化每个模块的麻烦。From www.pygame.org
Furthemore, here we can see that it's safe to do it in the beginning:
And finally, the main reason in my opinion as for why it is always used in the beginning:
So the main conclusion is that
pygame.init()
safely initializes all imported pygame modules regardless if the modules actually need to be initialized; but since it does for the ones that do, it saves the trouble of manually initializing each module individually.