0

I am trying to display a tiled map in pygame and i want to use pngs because they're transparent however, when i blit the tiles onto the window 4/6 different tiles display fine but 2 tiles don't display(grass on top and dirt in the center). When i try to do the same thing with jpegs the map displays fine but since they're not transparent i don't want to use them.

This is what the jpegs display: https://gyazo.com/f4bcd87763ebdcb718759cdc3e5132ba

This is what the pngs display: https://gyazo.com/df286b8d6f23d0f622de097eb423ea7c

Also i get spammed with this message: "libpng warning: iCCP: known incorrect sRGB profile" but i have been told that it is unimportant.

mainGame.py

import pygame
from settings import *
from Loading import *
from characters import *
import pytmx

pygame.init()

class game():

    def __init__(self):

        self.gameRunning = True
        self.gameWindow = pygame.display.set_mode((gameWindowWidth, gameWindowHeight))
        self.clock = pygame.time.Clock()
        self.playerSpeed = speed
        self.preloadedData = load()

    def update(self):

        pygame.display.set_caption("{:.2f}".format(self.clock.get_fps()))
        #self.gameWindow.blit(self.preloadedData["distantCity"], (0,0))
        self.gameWindow.blit(self.preloadedData["ninjaIdle01"], (player1.playerX, player1.playerY))
        pygame.display.update()

    def loadMap(self):

        self.map = tiledMap()
        self.map_img = self.map.make_map()
        self.gameWindow.blit(self.map_img, (0,624))

    def gameLoop(self):

        self.clock.tick(FPS)
        self.event()
        self.update()
        self.loadMap()

    def event(self):

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.gameRunning = False

            if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                self.playerSpeed = 5
            if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                self.playerSpeed = -5
            if event.type == pygame.KEYUP and event.key == pygame.K_RIGHT:
                self.playerSpeed = 0
            if event.type == pygame.KEYUP and event.key == pygame.K_LEFT:
                self.playerSpeed = 0

        player1.playerX = player1.playerX + self.playerSpeed

playGame = game()
player1 = player()
while playGame.gameRunning == True:
    playGame.gameLoop()


pygame.quit()
quit()

loading.py

import pygame
import pytmx

pygame.init()

def load():

    loaded = {}
    loaded["ninjaIdle01"] = pygame.image.load("gameImages\s_ninjaIdle_01.png")
    loaded["ninjaIdle02"] = pygame.image.load("gameImages\s_ninjaIdle_02.png")
    loaded["ninjaIdle03"] = pygame.image.load("gameImages\s_ninjaIdle_03.png")
    loaded["ninjaIdle04"] = pygame.image.load("gameImages\s_ninjaIdle_04.png")
    loaded["ninjaIdle05"] = pygame.image.load("gameImages\s_ninjaIdle_05.png")
    loaded["ninjaIdle06"] = pygame.image.load("gameImages\s_ninjaIdle_06.png")
    loaded["ninjaIdle07"] = pygame.image.load("gameImages\s_ninjaIdle_07.png")
    loaded["ninjaIdle08"] = pygame.image.load("gameImages\s_ninjaIdle_08.png")
    loaded["ninjaIdle09"] = pygame.image.load("gameImages\s_ninjaIdle_09.png")
    loaded["ninjaIdle10"] = pygame.image.load("gameImages\s_ninjaIdle_10.png")
    loaded["ninjaJump01"] = pygame.image.load("gameImages\s_ninjaJump_01.png")
    loaded["ninjaJump02"] = pygame.image.load("gameImages\s_ninjaJump_02.png")
    loaded["ninjaJump03"] = pygame.image.load("gameImages\s_ninjaJump_03.png")
    loaded["ninjaJump04"] = pygame.image.load("gameImages\s_ninjaJump_04.png")
    loaded["ninjaJump05"] = pygame.image.load("gameImages\s_ninjaJump_05.png")
    loaded["ninjaJump06"] = pygame.image.load("gameImages\s_ninjaJump_06.png")
    loaded["ninjaJump07"] = pygame.image.load("gameImages\s_ninjaJump_07.png")
    loaded["ninjaJump08"] = pygame.image.load("gameImages\s_ninjaJump_08.png")
    loaded["ninjaJump09"] = pygame.image.load("gameImages\s_ninjaJump_09.png")
    loaded["ninjaJump010"] = pygame.image.load("gameImages\s_ninjaJump_10.png")
    loaded["ninjaRun01"] = pygame.image.load("gameImages\s_ninjaRun_01.png")
    loaded["ninjaRun02"] = pygame.image.load("gameImages\s_ninjaRun_02.png")
    loaded["ninjaRun03"] = pygame.image.load("gameImages\s_ninjaRun_03.png")
    loaded["ninjaRun04"] = pygame.image.load("gameImages\s_ninjaRun_04.png")
    loaded["ninjaRun05"] = pygame.image.load("gameImages\s_ninjaRun_05.png")
    loaded["ninjaRun06"] = pygame.image.load("gameImages\s_ninjaRun_06.png")
    loaded["ninjaRun07"] = pygame.image.load("gameImages\s_ninjaRun_07.png")
    loaded["ninjaRun08"] = pygame.image.load("gameImages\s_ninjaRun_08.png")
    loaded["ninjaRun09"] = pygame.image.load("gameImages\s_ninjaRun_09.png")
    loaded["ninjaRun10"] = pygame.image.load("gameImages\s_ninjaRun_10.png")
    loaded["distantCity"] = pygame.image.load("gameImages\s_distantCity.png").convert()
    return loaded

class tiledMap():
    def __init__(self):
        self.gameMap = pytmx.load_pygame("s_gameMapJPG.tmx", pixelalpha=True)
        self.mapwidth = self.gameMap.tilewidth * self.gameMap.width
        self.mapheight = self.gameMap.tileheight * self.gameMap.height

    def render(self, surface):
        for layer in self.gameMap.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                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 make_map(self):
        mapSurface = pygame.Surface((640, 96))
        self.render(mapSurface)
        return mapSurface

s_gameMap.tmx

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="20" height="3" tilewidth="32" tileheight="32" nextobjectid="1">
 <tileset firstgid="1" name="isTiles" tilewidth="32" tileheight="32" tilecount="6" columns="0">
  <tile id="0">
   <image width="32" height="32" source="gameImages/s_grassLeft.png"/>
  </tile>
  <tile id="1">
   <image width="32" height="32" source="gameImages/s_grassMiddle.png"/>
  </tile>
  <tile id="2">
   <image width="32" height="32" source="gameImages/s_grassRight.png"/>
  </tile>
  <tile id="3">
   <image width="32" height="32" source="gameImages/s_dirtLeft.png"/>
  </tile>
  <tile id="4">
   <image width="32" height="32" source="gameImages/s_dirtMiddle.png"/>
  </tile>
  <tile id="5">
   <image width="32" height="32" source="gameImages/s_dirtRight.png"/>
  </tile>
 </tileset>
 <layer name="Tile Layer 1" width="20" height="3">
  <data encoding="csv">
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6
</data>
 </layer>
</map>

s_gameMapJPG.tmx

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="20" height="3" tilewidth="32" tileheight="32" nextobjectid="1">
 <tileset firstgid="1" name="small jpeg tiles" tilewidth="32" tileheight="32" tilecount="6" columns="0">
  <tile id="0">
   <image width="32" height="32" source="gameImages/s_grassRightJPG.jpg"/>
  </tile>
  <tile id="1">
   <image width="32" height="32" source="gameImages/s_grassMiddleJPG.jpg"/>
  </tile>
  <tile id="2">
   <image width="32" height="32" source="gameImages/s_grassLeftJPG.jpg"/>
  </tile>
  <tile id="3">
   <image width="32" height="32" source="gameImages/s_dirtRightJPG.jpg"/>
  </tile>
  <tile id="4">
   <image width="32" height="32" source="gameImages/s_dirtMiddleJPG.jpg"/>
  </tile>
  <tile id="5">
   <image width="32" height="32" source="gameImages/s_dirtLeftJPG.jpg"/>
  </tile>
 </tileset>
 <layer name="Tile Layer 1" width="20" height="3">
  <data encoding="csv">
3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,
6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4
</data>
 </layer>
</map>
  • add png image to see problem – furas Jan 26 '17 at 13:19
  • Sorry but could you clarify, what do you mean by add png image? – CustomerSupport Jan 26 '17 at 13:25
  • add png image with grass so we could check code with this sRGB profile. Maybe it has something to do with this problem. – furas Jan 26 '17 at 13:32
  • BTW: did you try with different PNG which doesn't show message about sRGB profiel. Or did you try to conver this PNG to RGB or RGBA ? – furas Jan 26 '17 at 13:37
  • heres a download link to one of the images that isn't working: https://www.dropbox.com/s/osj744oucagfn9w/grassMiddle.png?dl=0 the only difference i have noticed between the working images and the ones that didn't work, the ones that didn't work had no transparent parts and the ones that did work had some transparent parts on them, if that helps atall. – CustomerSupport Jan 27 '17 at 00:01
  • I tried this image, I saw warning `"libpng warning: iCCP:"` (first time in my life :) but it works for me on Linux. But it can depends on system. I used `ImageMagic` to convert `png` into `png` so I got smaller file and after that it doesn't show warning. I used `ImageMagic` to display some information about both file and they are identical except "Profile-icc" - my version doesn't have it. https://www.imagemagick.org/script/identify.php – furas Jan 27 '17 at 02:34
  • So, should i try and convert my images from png to png using ImageMagick and see if that works? – CustomerSupport Jan 27 '17 at 03:28
  • yes, try to convert file (with any program) and maybe you get version without `Profile` and then try to display it. – furas Jan 27 '17 at 03:32
  • Okay, solved my problem, i tried removing the alpha channel from those images as they had no visible transparency and for some reason that fixed my issue, Thanks for the help with sorting my profile issue. – CustomerSupport Jan 27 '17 at 05:13

1 Answers1

0

Put trans="ffffff" each terrain

<image width="32" height="32" trans="ffffff" source="gameImages/s_grassLeft.png"/>
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46