1
\$\begingroup\$

I have a part in my program that should display the currently playing song's name for the first 4 seconds, then fade out. Even though Surface.get_alpha() returns expected results, the image still does not fade out.

Why is this? How can I make it work?


My code looks like this:

for event in settings.events:
    if pygame.mixer.music.get_pos() < 4000 and sounds.music.volume != 0:
        #This part creates the surface and determines the position 
        show = 40 * 4
        font = pygame.font.SysFont(typeface, 15)
        songname = font.render(sounds.music.playlist[0], True, settings.color)
        font_pos = songname.get_rect()
        font_pos.right = screenx - 10
        font_pos.top = 10
        alpha = 255
    if event.type == USEREVENT + 1 and sounds.music.volume != 0:
        #The userevent is there to ensure it will fade out with the same speed
        #and not being related to fps
        #this decreases alpha
        show -= 1 if show > 0 else False
        if show < 40 * 4 and alpha > 0:
            alpha -= 1.6
        songname.set_alpha(int(alpha))

if pygame.mixer.music.get_volume() != 0.0 and show != 0:
    #This does actually return the correct results
    print songname.get_alpha(), alpha
    screen.blit(songname, font_pos)
\$\endgroup\$
5
  • 1
    \$\begingroup\$ blit is a bit level copy, it doesn't care about transparency \$\endgroup\$ Apr 16, 2015 at 20:42
  • \$\begingroup\$ @ratchetfreak I think that would make a good answer. \$\endgroup\$ Apr 16, 2015 at 20:50
  • \$\begingroup\$ @ratchetfreak How do I change transparency then? Because there are many other parts of the game witch use set_alpha() but when blitted the alpha is actually displayed. \$\endgroup\$
    – Pixdigit
    Apr 17, 2015 at 18:31
  • \$\begingroup\$ If this answers your question, we'll close this question with a link to the question on SO. \$\endgroup\$
    – House
    Apr 18, 2015 at 17:51
  • \$\begingroup\$ @Byte56 It does. But I don't know how to link it properly. \$\endgroup\$
    – Pixdigit
    Apr 19, 2015 at 11:28

0

You must log in to answer this question.

Browse other questions tagged .