Ruslan Osipov
Ruslan Osipov

Reputation: 5843

set_alpha() for partially transparent surface

I am trying to do this:

surface_with_text = pygame.font(params).render(params) # transparent bg
surface_with_text.set_alpha(100) # make it half transparent
another_surface.blit(surface_with_text) # blit onto image

But, of course, it silently fails - my text is still fully opaque... Why so? How do I find a workaround?

Of course I can blit "255 - 100"-transparent another_surface copy on the top of the text, but what fun is that, right?

Upvotes: 0

Views: 636

Answers (1)

Amber
Amber

Reputation: 526543

The rendered font surface is already using per-pixel alpha values (otherwise, it'd have a solid background).

From the Font.render doc:

If the background is transparent a pixel alpha will be included.

From the set_alpha doc:

This value is different than the per pixel Surface alpha. If the Surface format contains per pixel alphas, then this alpha value will be ignored.

Upvotes: 1

Related Questions