当我在基于 pygame 的游戏中使用精灵时,它们似乎无法正常工作 - 正如您在屏幕截图中看到的那样,它们的形状不正确并且上部有一些奇怪的变形。
加载图像所涉及的一段代码(从 pygame 的教程中复制粘贴):
def load_image(name, colorkey=None):
fullname = os.path.join('data', 'images')
fullname = os.path.join(fullname, name)
try:
image = pygame.image.load(fullname)
except pygame.error as message:
print('Cannot load image:', fullname)
raise SystemExit(message)
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
我一直在 Mac OS X 上的 Python 2.7.11 和 3.4.2 上做我的项目并遇到了这个问题。但是当我在 Windows 上的 Python 3.1 上测试它时,问题没有出现并且精灵加载正常。所以我认为这与 Mac OS X 有关。