StarArawn / bevy_ecs_tilemap

A tilemap rendering crate for bevy which is more ECS friendly.
MIT License
902 stars 195 forks source link

Hexagonal tmx map will not render correctly #403

Open darkautism opened 1 year ago

darkautism commented 1 year ago

In Tiled Editor:

image

In Bevy ecs tilemap:

image

This is t1.png

t1

This is tmx file

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.0" orientation="hexagonal" renderorder="right-down" width="18" height="10" tilewidth="48" tileheight="54" infinite="0" hexsidelength="26" staggeraxis="y" staggerindex="odd" nextlayerid="2" nextobjectid="1">
 <tileset firstgid="1" name="t1" tilewidth="48" tileheight="54" tilecount="1" columns="1">
  <image source="tiles/t1.png" width="48" height="54"/>
 </tileset>
 <layer id="1" name="Layer 1" width="18" height="10">
  <data encoding="base64" compression="zstd">
   KLUv/WDQAeUBAFAAAQEAAQEBAQEBHaCAfWADSeohACiwECWHwVncQwOrX2HuohFAI8zdiZaXlO5S+myG50vazEDnIKfTOw==
  </data>
 </layer>
</map>

This is bevy_ecs_tilemap version

tiled = "0.11.0" bevy_ecs_tilemap = { git = "https://github.com/StarArawn/bevy_ecs_tilemap.git", branch = "main" }

rparrett commented 1 year ago

Are you able reproduce this with the in-repo tiled example and tiled 0.10?

Also, it looks like perhaps you've uploaded the first screenshot twice by mistake rather than t1.png.

darkautism commented 1 year ago

Reupload t1.png in-repo helper has path bug if tmx more deeper image

It has x not flip bugs(I already fix in OP) image

darkautism commented 1 year ago

Maybe i should extend TilemapBundle's map_size to double times and change every TilePos's x ?

rparrett commented 1 year ago

It looks like the current example code assumes HexCoordSystem::Row, which is an "even" stagger, but the Tiled map settings above are staggerindex="odd".

You want to use HexCoordSystem::RowOdd or change the setting in Tiled.

rparrett commented 1 year ago

I don't think we can fix this in the example until functionality is added to tiled. https://github.com/mapeditor/rs-tiled/issues/261

darkautism commented 1 year ago

I have a WIP branch about staggeraxis. I'll send PR after fix all founded bugs.

darkautism commented 1 year ago

https://github.com/mapeditor/rs-tiled/pull/262

darkautism commented 1 year ago

Finally fix this, but i found some strange.

Why I need swap RowOdd <-> RowEven and ColumnOdd <->ColumnEven then It render correctly?

https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/helpers/tiled.rs#L263

-                           TilemapType::Hexagon(HexCoordSystem::Row)
+                           tiled::Orientation::Hexagonal => match tiled_map.map.staggeraxis {
+                               StaggerAxis::X => match tiled_map.map.staggerindex {
+                                   StaggerIndex::Even => {
+                                       TilemapType::Hexagon(HexCoordSystem::ColumnOdd)
+                                   }
+                                   StaggerIndex::Odd => {
+                                       TilemapType::Hexagon(HexCoordSystem::ColumnEven)
+                                   }
+                               },
+                               StaggerAxis::Y => match tiled_map.map.staggerindex {
+                                   StaggerIndex::Even => {
+                                       TilemapType::Hexagon(HexCoordSystem::RowOdd)
+                                   }
+                                   StaggerIndex::Odd => {
+                                       TilemapType::Hexagon(HexCoordSystem::RowEven)
+                                   }
+                               },
+                           },

https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/examples/helpers/tiled.rs#L280

-                                 if tiled_map.map.orientation == tiled::Orientation::Orthogonal {
+                                if tiled_map.map.orientation == tiled::Orientation::Orthogonal
+                                   || tiled_map.map.orientation == tiled::Orientation::Hexagonal
+                                {
rparrett commented 1 year ago

Could you do a separate PR to update our tiled dependency to 0.11?