我正在尝试使用以下代码将透明图像加载到 pygame 中:
def load_image(name, colorkey=None):
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
except pygame.error, 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()
出于某种原因,每次我加载图像时,背景都会自动变为黑色?在这种情况下,我没有使用颜色键,因为我的图像最终会在它们周围出现一个白色边框,考虑到我的游戏背景不断变化,这非常明显。
有任何想法吗?
感谢和问候