0

I have 6 png files, 4 of them have transparent edges. When i try to display them in my pygame window, the images display fine, however they just show black edges instead of transparent edges.

What the images look like in GIMP: https://gyazo.com/4a5f6bec01e4b524a3be5d6389ff0cce

What the images look like in tiled: https://gyazo.com/b2570ec9c89d2eac113f534da913305e

What the output in pygame is: 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>
  • I think it may be an issue with pytmx, not your code (though I may be wrong). You may be able to find the issue just by looking at its source code. – Douglas Feb 01 '17 at 14:19
  • i know that it used to work(when using the pixelalpha argument included). Do you know if there is there a way to get an older version of a pytmx whl that i could install? – CustomerSupport Feb 01 '17 at 15:34
  • Here are all the versions of PyTMX on GitHub: https://pypi.python.org/pypi/PyTMX – Douglas Feb 01 '17 at 16:53

0 Answers0