How can I use the alpha channel un Pygame?

dawn

I mean, in Python. The transparency. I simply want to an image appear and slowly vanish, aka, get transparent.

My actual code.

def post_texto_1():
inicio = True
alpha = 255

screen.fill((0, 0, 0))

while inicio:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

    imagen_postTexto1.set_alpha(alpha)
    screen.blit(imagen_postTexto1, (0, 0))
    alpha -= 1
    if alpha == 0:
        inicio = False
    tex2 = u"¿Dónde estoy? ¿A dónde voy?"
    mostrar_mensaje(tex2, (255, 255, 255))
    print("El alpha de la imagen es : "+str(alpha))
    pygame.display.update()
elegent

When you use convert_alpha(), you change the pixel format of an image including per pixel alphas.

According to the PyGame documentation for set_alpha(), the alpha value will be ignored, if the Surface format (i.e. the image) contains per pixel alphas.

If you still need to display a transparent image and want to use set_alpha(), you could use PyGames set_colorkey() method to set one color transparent.

Use the following function to vanish an image:

def vanish_image(image, screen, background_color):  
    image = pygame.image.load(image).convert()
    image.set_colorkey((0,0,0)) #RGB-value for transparent color if needed

    alpha = 255

    while True:        
        if alpha < 0: #exit function if alpha is smaller than 0
            return

        alpha -= 1

        screen.fill(background_color) #"clear" last blitted image
        image.set_alpha(alpha)

        pygame.display.update(screen.blit(image,(0,0))) #blit new image onto surface and update only this area

        pygame.time.delay(20) #wait 20 milliseconds

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to render transparent text with alpha channel in PyGame?

From Dev

How to use GraphicsMagick to negate the alpha channel of a picture

From Dev

How to use GraphicsMagick to negate the alpha channel of a picture

From Dev

How can I prevent Photoshop from adding an alpha channel to grayscale PNGs?

From Dev

How can I use channel send direction in Go

From Dev

I can't see the textures behind a texture with alpha channel

From Dev

How do I draw an image with an alpha channel to a TSpeedButton?

From Dev

How can I combine alpha with compositing in Images?

From Dev

How can I set alpha color on Robocode?

From Dev

How can I explicitly empty a channel?

From Java

discord.py (rewrite) How can I narrow a commands use ability to a single channel?

From Dev

Can I have a lower version code at production from alpha testing channel

From Dev

Can you remove the alpha channel in a PNG with SIPS?

From Dev

How can you test a video with alpha channel before merging it with another video?

From Dev

How do I use Sprite Sheets in Pygame?

From Dev

How can I implement pygame.sprite.spritecollide to my pygame

From Java

Using SIMD, how do I conditionally move only the pixels with an alpha channel value of 255?

From Dev

How can I exit Fullscreen mode in Pygame?

From Dev

How can I install Pygame to Pycharm?

From Dev

how can I reflect the screen in pygame

From Dev

How to apply alpha channel on drawPixmap with SourceOver

From Dev

How to remove opacity but keep the alpha channel of UIImage?

From Dev

How to read an animated gif with alpha channel

From Dev

How to change the alpha channel of an existing background color

From Dev

WebGL: How to correctly blend alpha channel png

From Dev

How to display a TBitmap with alpha channel on TImage correctly?

From Dev

How to remove opacity but keep the alpha channel of UIImage?

From Dev

How to apply alpha channel on drawPixmap with SourceOver

From Dev

OpenCV cv::cvtColor drops alpha channel, How to keep alpha data?

Related Related

  1. 1

    How to render transparent text with alpha channel in PyGame?

  2. 2

    How to use GraphicsMagick to negate the alpha channel of a picture

  3. 3

    How to use GraphicsMagick to negate the alpha channel of a picture

  4. 4

    How can I prevent Photoshop from adding an alpha channel to grayscale PNGs?

  5. 5

    How can I use channel send direction in Go

  6. 6

    I can't see the textures behind a texture with alpha channel

  7. 7

    How do I draw an image with an alpha channel to a TSpeedButton?

  8. 8

    How can I combine alpha with compositing in Images?

  9. 9

    How can I set alpha color on Robocode?

  10. 10

    How can I explicitly empty a channel?

  11. 11

    discord.py (rewrite) How can I narrow a commands use ability to a single channel?

  12. 12

    Can I have a lower version code at production from alpha testing channel

  13. 13

    Can you remove the alpha channel in a PNG with SIPS?

  14. 14

    How can you test a video with alpha channel before merging it with another video?

  15. 15

    How do I use Sprite Sheets in Pygame?

  16. 16

    How can I implement pygame.sprite.spritecollide to my pygame

  17. 17

    Using SIMD, how do I conditionally move only the pixels with an alpha channel value of 255?

  18. 18

    How can I exit Fullscreen mode in Pygame?

  19. 19

    How can I install Pygame to Pycharm?

  20. 20

    how can I reflect the screen in pygame

  21. 21

    How to apply alpha channel on drawPixmap with SourceOver

  22. 22

    How to remove opacity but keep the alpha channel of UIImage?

  23. 23

    How to read an animated gif with alpha channel

  24. 24

    How to change the alpha channel of an existing background color

  25. 25

    WebGL: How to correctly blend alpha channel png

  26. 26

    How to display a TBitmap with alpha channel on TImage correctly?

  27. 27

    How to remove opacity but keep the alpha channel of UIImage?

  28. 28

    How to apply alpha channel on drawPixmap with SourceOver

  29. 29

    OpenCV cv::cvtColor drops alpha channel, How to keep alpha data?

HotTag

Archive