Mar-13-2022, 09:12 AM
Dear community,
I display a paddle and a ball in a breakout game.
I've got an error concerning the display of the paddle.
Both pictures (ball + paddle) have got a transparent background.
The ball is displayed correctely - the paddle not (it has a white rectangle as background).
Online I read that I have to you use "convert_alpha()" to display pictures with a transparent background...
I attached ball.png and paddle.png.
In addition to that I attached the wrong display.
Would you please have a look at these files and perhaps tell me what's wrong with paddle.png?
I display a paddle and a ball in a breakout game.
I've got an error concerning the display of the paddle.
Both pictures (ball + paddle) have got a transparent background.
The ball is displayed correctely - the paddle not (it has a white rectangle as background).
Online I read that I have to you use "convert_alpha()" to display pictures with a transparent background...
I attached ball.png and paddle.png.
In addition to that I attached the wrong display.
Would you please have a look at these files and perhaps tell me what's wrong with paddle.png?
def create_image(file, color=None): """ Create image from a file. If color is specified, replace all FOREGROUND pixels with color pixels. Modify image so TRANSPARENT colored pixels are transparent. """ if color: # Recolor the image image = Image.open(file).convert("RGB") for xy in product(range(image.width), range(image.height)): if image.getpixel(xy) == FOREGROUND: image.putpixel(xy, color) image = pygame.image.fromstring(image.tobytes(), image.size, "RGB") else: image = pygame.image.load(file) image.set_colorkey(TRANSPARENT) return image.convert_alpha()