简体   繁体   中英

How does Godot manage to be fast with GDScript while Pygame is so slow with Python?

我看到有人抱怨 Pygame 怎么这么慢,后端使用 C 和 SDL,Godot 似乎即使使用类似 Python 的语言也有很好的性能。

Godot is a game engine while Pygame is a cross-platform set of Python modules.

Game engines handle a lot of stuff related to game loop under the hood using a low level compiled language like C/C++. This means that developers can write scripts with higher level languages like C# or GDScript that contain methods that get invoked by the engine at certain points of the execution. The engine itself handles rendering, updating physics, polling for inputs and whatnot.

With Pygame you're likely writing the game loop yourself and calling bunch of libraries to poll for inputs, draw/render graphics, update physics etc. This means that a bigger chunk of the execution time gets spent executing python scripts than say GDScripts in Godot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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