【问题标题】:Why are my pygame images not getting the alpha set after changing from windows to mac为什么我的 pygame 图像在从 windows 更改为 mac 后没有设置 alpha
【发布时间】:2014-01-04 11:17:43
【问题描述】:

这些是相关的代码部分:

class t_color(object):
    BLUE = (0, 0, 255)
    GREY = (128, 128, 128)
    GREEN = (0, 128, 0)
    LIME = (0, 255, 0)
    PURPLE = (128, 0, 128)
    RED = (255, 0, 0)
    SILVER = (192, 192, 192)
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    YELLOW = (255, 255, 0)

IMAGE_ALPHA = t_color.BLACK
...
img = pygame.image.load('images/' + str(i) + '.bmp')
img.set_colorkey(IMAGE_ALPHA)
g.images.append(img)

在 Windows 上,这工作正常。现在我使用的是 Mac (10.9) 和 python 2.7.5(在 windows 上我有 2.7.6)pygame 1.9.2(在 windows 上我有 1.9.1)

这是我正在使用的图片,它们只有 32x32 像素:http://www.mediafire.com/download/nf9exc8trged687/images.zip

我想将黑色设置为透明,因为图像是 BMP 文件并且不支持透明度。

有谁知道这是什么原因造成的或如何解决?

【问题讨论】:

  • /other 中的图像没有用于 alpha,它只是我游戏的一部分。
  • 在 linux 上使用 1.9.1 对我来说很好。
  • 我知道,它在 windows 上也适用于我,只是在 mac 上不行:\
  • 你在mac上试过pygame 1.9.1版本而不是1.9.2吗?
  • 无法安装 1.9.1,安装程序说我需要 python 2.7?即使我有 2.7.5。 ://

标签: python windows macos pygame alpha


【解决方案1】:

https://stackoverflow.com/a/13078080/3157252 -- 不是我的,找到了

有每像素 alpha、colorkey alpha 和每表面 alpha。你要的是颜色键。

当您调用 convert_alpha() 时,它会为每像素 alpha 创建一个新表面。

来自set_colorkey

如果 Surface 被格式化为使用每像素 alpha 值,则颜色键将被忽略。

所以:使用.convert() 加载图像因为您想使用颜色键。然后拨打set_colorkey

另外,我在文档中没有看到关于将“-1”作为第一个参数传递给 set_colorkey。

这可能来自一个教程,其中有一个 load_image 函数来获取左上角像素的颜色值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多