Reputation: 311
This is supposed to just load a sprite onto the screen, but the background of the image is this black box, and i don't want to see that. How do I make the background of the image transparent?
from Tkinter import *
import pygame
from livewires import games
#Creating screen window
games.init(screen_width = 700, screen_height = 650, fps = 50)
#creating background image for the screen
screen_background = games.load_image('resized_stars background.png', transparent = False)
games.screen.background = screen_background
#Creating a sprite
spaceship_image = games.load_image('pixel_spaceship.png')
spaceship = games.Sprite(image = spaceship_image, x=350, y=235)
games.screen.add(spaceship)
#main loop at the end of the program just as in tkinter
games.screen.mainloop()
Upvotes: 1
Views: 3018
Reputation: 11
When loading the png image, you have to convert it:
image = pygame.image.load("yourImage.png").convert_alpha()
This should get rid of that black box that should be the transparent alpha.
Upvotes: 0
Reputation: 19264
Your image needs to be a png. Open Preview, for example, and use the alpha tool to remove the background, thus adding transparency.
Before png:
After png:
Look here for a tool on making your picture transparent.
Upvotes: 1