mirror of https://github.com/axmolengine/axmol.git
Merge pull request #16165 from ricardoquesada/issue_16105_bis
fix: stagger tilemaps hexa works as expected
This commit is contained in:
commit
62f1762ea9
|
@ -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<int>(_layerSize.width/2))
|
||||
newX = (x - static_cast<int>(_layerSize.width/2)) * 2;
|
||||
else
|
||||
newX = x * 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int pos = static_cast<int>(newX + _layerSize.width * y);
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -370,5 +370,13 @@ public:
|
|||
|
||||
};
|
||||
|
||||
class Issue16105Test : public TileDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue16105Test);
|
||||
Issue16105Test();
|
||||
virtual std::string title() const override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.0" orientation="hexagonal" renderorder="right-down" width="13" height="4" tilewidth="80" tileheight="80" hexsidelength="40" staggeraxis="x" staggerindex="odd" nextobjectid="1">
|
||||
<tileset firstgid="1" name="tiles-ground" tilewidth="80" tileheight="80" tilecount="2" columns="2">
|
||||
<image source="hexa-axis-x.png" width="160" height="80"/>
|
||||
<tile id="0">
|
||||
<properties>
|
||||
<property name="collidable" type="bool" value="true"/>
|
||||
<property name="name" value="Plain"/>
|
||||
</properties>
|
||||
</tile>
|
||||
<tile id="1">
|
||||
<properties>
|
||||
<property name="collidable" type="bool" value="false"/>
|
||||
<property name="name" value="Rock"/>
|
||||
</properties>
|
||||
</tile>
|
||||
</tileset>
|
||||
<layer name="ground" width="13" height="4" opacity="0.2">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjZGBgYIRiJjQaH2ZCU4+OCenHZRax6nHJAQAcSABB
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Loading…
Reference in New Issue