Python Forum
How to display isometric maps with pytmx?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to display isometric maps with pytmx?
#1
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
Reply
#2
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?
Recommended Tutorials:
Reply
#3
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))
Reply
#4
(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...2676050483
https://www.photobox.co.uk/my/photo/full...2676048558
Reply
#5
all those links just take me to the main photobox page. I registered and now they just take me to my page. Have github?
Reply
#6
why dont you just upload the images to this forum?
Recommended Tutorials:
Reply
#7
(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
Reply
#8
Add attachment at bottom.
Reply
#9
(Feb-04-2020, 02:24 PM)Piethon Wrote: How can I upload them onto this page?
Sorry
How to Attach a File
Recommended Tutorials:
Reply
#10
Here are the pics. How it looks and how it is supposed to look.
Hope you can see my problem now.

Thanks Smile

Attached Files

Thumbnail(s)
       
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Isometric game pygame Tiled howardberger 1 586 Jan-31-2024, 10:01 PM
Last Post: deanhystad
  [PyGame] Isometric Movement on Tiled Map Josselin 0 2,365 Nov-02-2021, 06:56 AM
Last Post: Josselin
Thumbs Up [PyGame] Simple code for isometric 2D games ThePhi 1 15,278 Nov-17-2020, 12:58 PM
Last Post: mattwins
  [split] How to display isometric maps with pygame? mattwins 6 6,237 Nov-17-2020, 12:54 PM
Last Post: mattwins
  Problems with pytmx Piethon 15 9,364 Jan-05-2020, 10:44 AM
Last Post: Piethon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020