【问题标题】:Can't create games with pygame无法使用 pygame 创建游戏
【发布时间】:2010-10-28 02:52:04
【问题描述】:

我用 python 2.5 和 pygame 制作了一个游戏。

但是,我无法完成制作。 因为发生了这个错误。

C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd
Traceback (most recent call last):
  File "Main.py", line 8, in <module>
  File "pygame\__init__.pyo", line 70, in __getattr__
NotImplementedError: font module not available
Traceback (most recent call last):
  File "Main.py", line 8, in <module>
  File "pygame\sysfont.pyo", line 253, in SysFont
RuntimeError: default font not found 'freesansbold.ttf'

也许我认为原因是因为它使用了一个名为 sysfont 的对象。 (因为我的程序在执行文件上没有使用 sysfont 并且能够从没有安装 Python 的 PC 启动) 怎么了 。 对不起,我是初学者。

编辑 我可以找到 Python2.5\Lib\site-packages\pygame\freesansbold.ttf

但发生了同样的错误.. 我可以在哪里复制 freesansbold.ttf

【问题讨论】:

    标签: python fonts pygame


    【解决方案1】:

    一个简单的解决方案是直接加载字体而不是使用 sysfont。只需使用 pygame.font.Font 类并直接加载一个 ttf 文件。这也将使 py2exe 更容易使用,并且您可以准确地选择您想要的字体。

    【讨论】:

      【解决方案2】:

      您的计算机上的可访问字体文件夹中似乎没有 freesansbold.ttf 文件。这个字体应该是 Pygame 自带的,在 lib 目录下。

      检查您的 Pygame 副本的安装文件夹,如果存在,请修改 Python 安装的字体路径以包含该目录。如果没有,您需要找到一个副本或下载更新版本的 Pygame。

      【讨论】:

      • 我可以找到 Python2.5\Lib\site-packages\pygame\freesansbold.ttf 但发生了同样的错误.. 我可以在哪里复制 freesansbold.ttf
      • 尝试将其复制到您的系统字体文件夹中,或者将它所在的文件夹添加到您的 Python 字体路径中。有关更多信息,请参阅此线程:echochamber.me/viewtopic.php?f=11&t=26064
      【解决方案3】:

      您可能找到了解决方案,但我想为其他解决方案提供一个。 用 pygame 创建你的游戏。然后,解压缩库文件。 去

      PythonX.X\Lib\site-packages\pygame 并复制 freesansbold.ttf

      回到你解压缩的库文件并转到

      库\pygame

      将 freesansbold.ttf 放入压缩包中。

      现在,它的工作! :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-18
        • 2021-03-20
        • 1970-01-01
        • 2013-06-21
        • 1970-01-01
        相关资源
        最近更新 更多