1

I'm trying to blit some fog into a game, but I've run into a problem where I've realized that the fog is too thick/opacity to high. I want to blit it with an even lower opacity, but I'm not too sure how and the tutorials I've found online don't work/already expect you to know how to.

Just in case you're wondering how the code is written:

screen.blit(fog, (0, 0))

EDIT: I'm using Python 3.8, just in case that matters

EDIT EDIT: I'm using Pygame 2.0.0, just in case that also matters

Duck Duck
  • 159
  • 6

2 Answers2

1

You don't blit at lower opacity, you blit a surface that has a lower opacity.

Use surface.set_alpha() to change the opacity of the fog before you blit it.

Docs: https://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_alpha

Also, if you're loading in your fog from an image, be sure to use surface.convert_alpha() on it, or else it will not register the transparency in the image format.

Starbuck5
  • 1,649
  • 2
  • 7
  • 13
0

blit() actually blends a Surface onto the target Surface, dependent on the alpha channel of the Surface. All you have to do is change the alpha channel of the fog. Use set_alpha() to set the alpha value for the full Surface image:

Set the current alpha value for the Surface. When blitting this Surface onto a destination, the pixels will be drawn slightly transparent. The alpha value is an integer from 0 to 255, 0 is fully transparent and 255 is fully opaque.

If you want to apply a 50% transparent fog:

fog.set_alpha(127)
screen.blit(fog, (0, 0))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174