我有6个png文件,其中4个有透明边缘。当我尝试在我的pygame窗口中显示它们时,图像显示正常,但它们只显示黑色边缘而不是透明边缘。
GIMP中的图像是什么样的:https://gyazo.com/4a5f6bec01e4b524a3be5d6389ff0cce
平铺图像的样子:https://gyazo.com/b2570ec9c89d2eac113f534da913305e
pygame中的输出是:https://gyazo.com/20fbf171ecdaee884df5e76e93040c68
main.py
import pygame
from settings import *
from loading import *
class game():
def __init__(self):
self.screen = pygame.display.set_mode((displayWidth, displayHeight))
pygame.display.set_caption(title)
self.clock = pygame.time.Clock()
self.gameRunning = True
def loop(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.gameRunning = False
def gameLoop(self):
self.clock.tick(fps)
self.loop()
self.loadMap()
self.editScreen()
def editScreen(self):
self.screen.fill(white)
self.screen.blit(self.map_img, (320,528))
pygame.display.update()
def loadMap(self):
self.map = tiledMap()
self.map_img = self.map.makeSurface()
playGame = game()
while playGame.gameRunning == True:
playGame.gameLoop()
loading.py
import pygame
import pytmx
pygame.init()
class tiledMap():
def __init__(self):
self.gameMap = pytmx.load_pygame("maps\_testingMap.tmx")
# I have also tried self.gameMap = pytmx.load_pygame("maps\_testingMap.tmx", pixelalpha=True)
self.mapWidth = self.gameMap.width * self.gameMap.tilewidth
self.mapHeight = self.gameMap.height * self.gameMap.tilewidth
def render(self, surface):
for layer in self.gameMap.visible_layers:
for x,y,gid in layer:
tile = self.gameMap.get_tile_image_by_gid(gid)
surface.blit(tile, (x * self.gameMap.tilewidth, y * self.gameMap.tileheight))
def makeSurface(self):
tiledSurface = pygame.Surface((self.mapWidth, self.mapWidth))
self.render(tiledSurface)
return tiledSurface
_testingMap.tmx
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="10" height="3" tilewidth="64" tileheight="64" nextobjectid="1">
<tileset firstgid="1" name="testingTileset" tilewidth="64" tileheight="64" tilecount="6" columns="0">
<tile id="0">
<image width="64" height="64" source="../images/m_dirtLeftFIX.png"/>
</tile>
<tile id="1">
<image width="64" height="64" source="../images/m_dirtMiddleFIXNA.png"/>
</tile>
<tile id="2">
<image width="64" height="64" source="../images/m_dirtRightFIX.png"/>
</tile>
<tile id="3">
<image width="64" height="64" source="../images/m_grassLeftFIX.png"/>
</tile>
<tile id="4">
<image width="64" height="64" source="../images/m_grassMiddleFIXNA.png"/>
</tile>
<tile id="5">
<image width="64" height="64" source="../images/m_grassRightFIX.png"/>
</tile>
</tileset>
<layer name="Tile Layer 1" width="10" height="3">
<data encoding="csv">
4,5,5,5,5,5,5,5,5,6,
1,2,2,2,2,2,2,2,2,3,
1,2,2,2,2,2,2,2,2,3
</data>
</layer>
</map>