[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] font alpha
Mike,
I don't think the blit to another surface is doing what you think it's doing.
Run your code again, but this time filling the screen to something
other than black, and you'll see what I mean.
List,
I think this is the 3rd time I've seen someone emailing this list
trying to figure out how to blit a per-pixel alpha surface with a
surface alpha. Since pygame does it's own SW alpha blending (apart
from SDL I mean) anyways, seems like supporting this case is something
pygame could do... would there be anything wrong or particularly hard
to do with making it so if you call set_alpha with alpha > 0 or < 255
on a per-pixel alpha surface, then blits with it use both surface
alpha and per-pixel?
#---------------------------------
# Mike's Code modified to use non-black screen
import pygame
import time
pygame.init()
screen = pygame.display.set_mode((640,480), pygame.SRCALPHA)
screen.fill((255,0,255))
myFont = pygame.font.Font(None, 30)
nonTransparent = myFont.render("This text should be fully opaque", 1,
(255,255,255))
screen.blit(nonTransparent, (0,0))
myText = 'This text should be somewhat transparent'
semiTransparent = myFont.render(myText, 1, (255,255,255))
newSurf = pygame.Surface(myFont.size(myText))
newSurf.blit(semiTransparent,(0,0))
newSurf.set_alpha(100)
screen.blit(newSurf, (0,100))
pygame.display.flip()
time.sleep(5)