如何使pygame精灵的背景透明

时间:2015-04-27 01:34:06

标签: python pygame

这应该只是将一个精灵加载到屏幕上,但图像的背景是这个黑盒子,我不想看到它。如何使图像的背景透明?

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()

1 个答案:

答案 0 :(得分:1)

您的图片必须是。例如,打开预览,并使用alpha工具删除背景,从而增加透明度。

之前

enter image description here

enter image description here

查看here有关使图片透明的工具。