pygame 是 python 的 2D 游戏开发库, 优点是秉承了 Python 风格, 简单好用
最近在 macOS High Sierra10.13.5 上安装 pygame 时遇到了一些问题:
pygame 无法检测鼠标键盘事件
用户无法聚焦到游戏窗口
docker 栏无法显示游戏图标
经过一晚上的折腾, 终于找到了正确的解决方法, 分享一下
解决方法:
通过 brew 安装依赖包
brew install sdl smpeg sdl_image sdl_mixer sdl_ttf portmidi hg sdl_mixer portmidi
安装 xquartz
https://www.xquartz.org/
pip 通过 github 源码安装 pygame
这一步非常关键, 如果使用 pip pygame 直接安装, docker 栏无法显示游戏的图标, 并且无法检测键盘事件
pip install https://github.com/pygame/pygame/archive/master.zip
官方 Demo 检验效果
python -m pygame.examples.aliens
来源: http://www.jianshu.com/p/d4f49767191e