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

Re: [pygame] font alpha



Ah, well eventually I'll be overlaying different font layers over top of one another so maybe you're right in that my solution is still unsatisfactory.

On 6-Sep-07, at 2:00 PM, Brian Fisher wrote:

haha...  I assumed you wanted something font letters with alpha - so
you had something that could be drawn over something other than a
solid color - but I guess you could always grab the background behind
where you want the text in a surface, blit the text over the piece of
the background you grabbed in the surface, then set alpha on the
background surface and blit that, and it would work for the effect you
want no matter the background.


On 9/6/07, Mike Lawrence <Mike.Lawrence@xxxxxx> wrote:
Rendering the semi-transparent text with the appropriate background
'seems' to make it work again.

#---------------------------------
# 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), (255,0,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)

--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University

Website: http://memetic.ca

Public calendar: http://icalx.com/public/informavore/Public

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
        - Piet Hein




--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University

Website: http://memetic.ca

Public calendar: http://icalx.com/public/informavore/Public

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
	- Piet Hein