diff --git a/cocos/2d/CCTMXLayer.cpp b/cocos/2d/CCTMXLayer.cpp index 4f9aa37152..c8f3a260e6 100644 --- a/cocos/2d/CCTMXLayer.cpp +++ b/cocos/2d/CCTMXLayer.cpp @@ -175,12 +175,19 @@ void TMXLayer::setupTiles() // fix correct render ordering in Hexagonal maps when stagger axis == x if (_staggerAxis == TMXStaggerAxis_X && _layerOrientation == TMXOrientationHex) { - int one_or_zero = (_staggerIndex == TMXStaggerIndex_Odd) ? 1 : 0; - int zero_or_one = one_or_zero ^ 1; - if (x >= (int)_layerSize.width/2) - newX = (x - (int)_layerSize.width/2) * 2 + one_or_zero; - else - newX = x * 2 + zero_or_one; + if (_staggerIndex == TMXStaggerIndex_Odd) + { + if (x >= _layerSize.width/2) + newX = (x - std::ceil(_layerSize.width/2)) * 2 + 1; + else + newX = x * 2; + } else { + // TMXStaggerIndex_Even + if (x >= static_cast(_layerSize.width/2)) + newX = (x - static_cast(_layerSize.width/2)) * 2; + else + newX = x * 2 + 1; + } } int pos = static_cast(newX + _layerSize.width * y); diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp index d692774879..a9ad85768e 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp @@ -54,6 +54,7 @@ TileMapTests::TileMapTests() ADD_TEST_CASE(TMXHexOddYTest); ADD_TEST_CASE(TMXHexEvenYTest); ADD_TEST_CASE(TMXHexAxisXTest); + ADD_TEST_CASE(Issue16105Test); } TileDemo::TileDemo() @@ -1606,3 +1607,25 @@ std::string TMXHexAxisXTest::title() const { return "The map should be same with in Tiled Editor"; } + +//------------------------------------------------------------------ +// +// Issue16105Test +// +//------------------------------------------------------------------ +Issue16105Test::Issue16105Test() +{ + auto color = LayerColor::create( Color4B(64,64,64,255) ); + addChild(color, -1); + + auto map = TMXTiledMap::create("TileMaps/issue16105.tmx"); + addChild(map, 0, kTagTileMap); + + Size CC_UNUSED s = map->getContentSize(); + CCLOG("ContentSize: %f, %f", s.width,s.height); +} + +std::string Issue16105Test::title() const +{ + return "Github Issue #16105"; +} diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h index e9d592a08c..b7bc937dcb 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest.h @@ -370,5 +370,13 @@ public: }; +class Issue16105Test : public TileDemo +{ +public: + CREATE_FUNC(Issue16105Test); + Issue16105Test(); + virtual std::string title() const override; + +}; #endif diff --git a/tests/cpp-tests/Resources/TileMaps/issue16105.tmx b/tests/cpp-tests/Resources/TileMaps/issue16105.tmx new file mode 100644 index 0000000000..f491a13fe8 --- /dev/null +++ b/tests/cpp-tests/Resources/TileMaps/issue16105.tmx @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + eJxjZGBgYIRiJjQaH2ZCU4+OCenHZRax6nHJAQAcSABB + + +