[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] alpha channel in font-rendered Surfaces
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] alpha channel in font-rendered Surfaces
- From: "Brendan Speer" <brendan.speer@xxxxxxxxx>
- Date: Thu, 15 Feb 2007 07:40:13 -0600
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 15 Feb 2007 08:40:31 -0500
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=KbRzasnJs6fjEqGYuuqqoI7sOUxs7uew/rcDvwggsmwYa8HmY7ZuUynIkwkaVUMB9w/eNOSGxwnHrPXusjQ2CxgBOvaVZX4HA9q2GM7BSOXPrgOybTMafdz7ywe3+TqzAc5XMgIQM1G6tF5okI98RLfp2VbMCfS4z9AUgGGkdaQ=
- In-reply-to: <45D42BD9.4050704@hapticanalysis.org>
- References: <45D42BD9.4050704@hapticanalysis.org>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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()
----------------