[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] alpha channel in font-rendered Surfaces



Hi,

I have a problem when trying to fade-in a text.

Using the alpha-channel when blitting in an image works fine, but not a surface generated by Font.render().

Below is a complete example, (using two external files test.png and freesansbold.ttf, replace with your own image and font).

I am new to pygame, so please bear with me.

Yours,

          Goran

---------

import pygame

pygame.init()

screensize = screenwidth, screenheight = 800, 600

# create a pygame "Surface" to draw on
screen = pygame.display.set_mode(screensize) # in window


screen.fill( (255,255,255) ) pygame.display.update() pygame.time.wait(1000)

testimage = pygame.image.load("test.png").convert()
pygame.font.init()

font = pygame.font.Font('freesansbold.ttf',40)
fontimage = font.render('TESTIMAGE',1,(0,0,0));
testimage2 = fontimage.convert_alpha()


alphaVector = range(0,255,10)

for alpha in alphaVector:
    testimage2.set_alpha( alpha )
    screen.blit( testimage2, (0,0))
    pygame.display.update()
    pygame.time.wait(50)
    print alpha

pygame.quit()
----------------