Transparent Sprites in Pygame

前端 未结 2 957
忘了有多久
忘了有多久 2021-01-15 02:07

I\'m working on some Python code that uses Pygame, trying to display a small sprite (a ball) on top of a background. I have that part working, but I\'m trying to get the bac

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-15 02:14

    There's per-pixel alpha, colorkey alpha, and per-surface alpha. You're asking for colorkey.

    When you call convert_alpha() it creates a new surface for per-pixel alpha.

    And from set_colorkey

    The colorkey will be ignored if the Surface is formatted to use per pixel alpha values.

    So: Load image with .convert() Since you want to use a color key. Then call set_colorkey.

    Also, I saw nothing in the docs about passing "-1" as first argument to set_colorkey.

    That's probably from a tutorial, which has a load_image function to grab the topleft pixel's color value.

提交回复
热议问题