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

Re: [pygame] alpha channel in font-rendered Surfaces



Surface.convert_alpha creates per-pixel alpha values.

From the Surface.set_alpha help: '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. If the Surface contains per pixel alphas, setting the alpha value to None will disable the per pixel transparency.'

In order to do what you're asking, you need to look at Sufarray. and manipulate each per-pixel alpha individually, or you can use convert() instead of convert_alpha() (I think...)

On 2/15/07, Goran <goran@xxxxxxxxxxxxxxxxxx> wrote:
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()
----------------