renpy / pygame_sdl2

Reimplementation of portions of the pygame API using SDL2.
GNU Lesser General Public License v2.1
327 stars 64 forks source link

Surface.set_alpha() doesn't work #23

Closed runedevros closed 8 years ago

runedevros commented 8 years ago

Hi there! We use translucent surfaces in order to apply a tint to images and do things like fade in and out. It looks like Pygame_SDL2's set_alpha() function on surfaces isn't working.

The following code draws a semi-transparent red box over a white box in Pygame:

screen shot 2016-01-23 at 5 06 02 pm

But it draws a solid red box in Pygame_SDL2:

screen shot 2016-01-23 at 5 06 28 pm

Code to reproduce it is below:

# Comment out these two lines to go back to old Pygame version
import pygame_sdl2
pygame_sdl2.import_as_pygame()

import pygame
from pygame import KEYDOWN, QUIT
import sys

def main():

    pygame.init()
    tilesize = 35
    size_x = 24
    size_y = 18
    screen_size = (tilesize * size_x, tilesize * size_y)
    screen = pygame.display.set_mode(screen_size, 0, 32)
    clock = pygame.time.Clock()

    stop_flag = False

    block = pygame.Surface((300,300))
    block.fill((255,255,255))

    overlay_block = pygame.Surface((300,300))
    overlay_block.fill((255,0,0))
    overlay_block.set_alpha(140)

    while not stop_flag:

        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()

        screen.fill((200,200,200))

        screen.blit(block, (50,50))
        screen.blit(overlay_block, (100,100))

        pygame.display.flip()
        clock.tick(60)

if __name__ == '__main__':
    main()