Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 为什么我的平铺贴图没有透明度?_Python 3.x_Pygame_Transparency_Tiled_Pytmx - Fatal编程技术网

Python 3.x 为什么我的平铺贴图没有透明度?

Python 3.x 为什么我的平铺贴图没有透明度?,python-3.x,pygame,transparency,tiled,pytmx,Python 3.x,Pygame,Transparency,Tiled,Pytmx,我有6个png文件,其中4个有透明的边缘。当我尝试在pygame窗口中显示它们时,图像显示良好,但是它们只显示黑色边缘,而不是透明边缘 GIMP中的图像是什么样子的: 平铺中图像的外观: pygame中的输出是: main.py import pygame from settings import * from loading import * class game(): def __init__(self): self.screen = pygame.display.

我有6个png文件,其中4个有透明的边缘。当我尝试在pygame窗口中显示它们时,图像显示良好,但是它们只显示黑色边缘,而不是透明边缘

GIMP中的图像是什么样子的:

平铺中图像的外观:

pygame中的输出是:

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()
加载.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>

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

我认为这可能是pytmx的问题,而不是您的代码(尽管我可能错了)。您可能只需查看其源代码就可以找到问题。我知道它过去是有效的(当使用包含的pixelalpha参数时)。你知道有没有办法获得我可以安装的pytmx whl的旧版本?以下是GitHub上pytmx的所有版本: