bevy_ecs_tilemap icon indicating copy to clipboard operation
bevy_ecs_tilemap copied to clipboard

Hexagonal tmx map will not render correctly

Open darkautism opened this issue 1 year ago • 9 comments

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" }

darkautism avatar Mar 22 '23 02:03 darkautism

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.

rparrett avatar Mar 22 '23 03:03 rparrett

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 avatar Mar 22 '23 03:03 darkautism

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

darkautism avatar Mar 22 '23 03:03 darkautism

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 avatar Mar 22 '23 04:03 rparrett

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

rparrett avatar Mar 22 '23 04:03 rparrett

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

darkautism avatar Mar 22 '23 04:03 darkautism

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

darkautism avatar Mar 22 '23 05:03 darkautism

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
+                                {

darkautism avatar Mar 22 '23 05:03 darkautism

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

rparrett avatar Mar 22 '23 15:03 rparrett