Python Forum
How to display isometric maps with pytmx? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: How to display isometric maps with pytmx? (/thread-24136.html)

Pages: 1 2


How to display isometric maps with pytmx? - Piethon - Feb-01-2020

Hello everybody,

I know, I have posted a bit different question a few months ago. Now that I can load my Map with pytmx, I have troubles displaying an isometric map with pytmx.

I am creating a game using the language python. For the game map, I have downloaded the "Tiled" Map Editor, which I used to make an isometric map. Now I wanted to load this isometric map into my python script using the python library "pytmx", which can read tmx map files. I searched through the whole internet, but I didn't found out, how to display an isometric map in python. What I've done, is trying to load the isometric map, with a script that is supposed to load orthodox maps (2D maps, top down). Of course, I could load the isometric map with it, but it looks stupid, cause it is not being displayed in an isometric perspective. So that's why it looks pretty stupid.
So here is the code, I have been using, to load the map:
import pygame as pg
import pytmx
from settings import *

class TiledMap:
    def __init__(self, filename):
        tm = pytmx.load_pygame(filename, pixelalpha=True)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tileheight
        self.tmxdata = tm

    def render(self, surface):
        ti = self.tmxdata.get_tile_image_by_gid
        for layer in self.tmxdata.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                for x, y, gid, in layer:
                    tile = ti(gid)
                    if tile:
                        surface.blit(tile, (x * self.tmxdata.tilewidth,
                                            y * self.tmxdata.tileheight))

    def make_map(self):
        temp_surface = pg.Surface((self.width, self.height))
        self.render(temp_surface)
        return temp_surface
So now my question: How do I need to transform that code above, that it is able to display isometric maps right?

Thank you so much for your help,

Piethon


RE: How to display isometric maps with pytmx? - metulburr - Feb-02-2020

I would assume the algorithm for drawing isometric VS orthogonal would be different. So you are going to have to modify the code. You did not specify the exact issue. Im assuming your issue is one sprite drawing over another that would not occur in orthogonal map? If so this answer explains the zig-zag approach.

Do you have a repo with the required graphics to run your game?


RE: How to display isometric maps with pytmx? - michael1789 - Feb-02-2020

I just spent some time looking around. And here https://readthedocs.org/projects/tiled/downloads/pdf/stable/I found this:

Quote:For most map types, objects are positioned in plain pixels. The only exception to this are isometric maps (not isometric staggered). For isometric maps, it was deemed useful to store their positions in a projected coordinate space. For this,the isometric tiles are assumed to represent projected squares with both sides equal to the tile height. If you’re using a different coordinate space for objects in your isometric game, you’ll need to convert these coordinates accordingly

Is it maybe this x, y, that needs converting "accordingly"? This means some sort of offset?
if tile:
    surface.blit(tile, (x * self.tmxdata.tilewidth,
                       y * self.tmxdata.tileheight))



RE: How to display isometric maps with pytmx? - Piethon - Feb-03-2020

(Feb-02-2020, 06:42 PM)michael1789 Wrote: Is it maybe this x, y, that needs converting "accordingly"? This means some sort of offset?
if tile:
    surface.blit(tile, (x * self.tmxdata.tilewidth,
                       y * self.tmxdata.tileheight))

Makes sense, but what do I need to change there then?
I just uploaded some photos of how it is looking and how it is supposed to look. Maybe you can see my problem then:

[Image: full?photo_id=502676050483]

That is how it is supposed to look
Now how it looks like:

[Image: full?photo_id=502676048558]

Thanks

PS: If you can't see the pictures, probably click onto the question markes or just on those links:
https://www.photobox.co.uk/my/photo/full?photo_id=502676050483
https://www.photobox.co.uk/my/photo/full?photo_id=502676048558


RE: How to display isometric maps with pytmx? - michael1789 - Feb-03-2020

all those links just take me to the main photobox page. I registered and now they just take me to my page. Have github?


RE: How to display isometric maps with pytmx? - metulburr - Feb-03-2020

why dont you just upload the images to this forum?


RE: How to display isometric maps with pytmx? - Piethon - Feb-04-2020

(Feb-03-2020, 08:01 PM)metulburr Wrote: why dont you just upload the images to this forum?

When I click onto the image icon, I need to insert an image url. How can I upload them onto this page?
Sorry


RE: How to display isometric maps with pytmx? - michael1789 - Feb-04-2020

Add attachment at bottom.


RE: How to display isometric maps with pytmx? - metulburr - Feb-04-2020

(Feb-04-2020, 02:24 PM)Piethon Wrote: How can I upload them onto this page?
Sorry
How to Attach a File


RE: How to display isometric maps with pytmx? - Piethon - Feb-05-2020

Here are the pics. How it looks and how it is supposed to look.
Hope you can see my problem now.

Thanks Smile