Merge pull request #16165 from ricardoquesada/issue_16105_bis

fix: stagger tilemaps hexa works as expected
This commit is contained in:
Ricardo Quesada 2016-07-20 05:06:31 -07:00 committed by GitHub
commit 62f1762ea9
4 changed files with 67 additions and 6 deletions

View File

@ -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);

View File

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

View File

@ -370,5 +370,13 @@ public:
};
class Issue16105Test : public TileDemo
{
public:
CREATE_FUNC(Issue16105Test);
Issue16105Test();
virtual std::string title() const override;
};
#endif

View File

@ -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>