mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8650 from dabingnn/v3_addStaggeredTileMap
V3 add staggered tile map
This commit is contained in:
commit
0351000c97
|
@ -618,6 +618,17 @@ Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos)
|
|||
case TMXOrientationHex:
|
||||
CCASSERT(pos.equals(Vec2::ZERO), "offset for hexagonal map not implemented yet");
|
||||
break;
|
||||
case TMXOrientationStaggered:
|
||||
{
|
||||
float diffX = 0;
|
||||
if ((int)abs(pos.y) % 2 == 1)
|
||||
{
|
||||
diffX = _mapTileSize.width/2;
|
||||
}
|
||||
ret = Vec2(pos.x * _mapTileSize.width + diffX,
|
||||
(-pos.y) * _mapTileSize.height/2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -636,6 +647,9 @@ Vec2 TMXLayer::getPositionAt(const Vec2& pos)
|
|||
case TMXOrientationHex:
|
||||
ret = getPositionForHexAt(pos);
|
||||
break;
|
||||
case TMXOrientationStaggered:
|
||||
ret = getPositionForStaggeredAt(pos);
|
||||
break;
|
||||
}
|
||||
ret = CC_POINT_PIXELS_TO_POINTS( ret );
|
||||
return ret;
|
||||
|
@ -666,6 +680,17 @@ Vec2 TMXLayer::getPositionForHexAt(const Vec2& pos)
|
|||
return xy;
|
||||
}
|
||||
|
||||
Vec2 TMXLayer::getPositionForStaggeredAt(const Vec2 &pos)
|
||||
{
|
||||
float diffX = 0;
|
||||
if ((int)pos.y % 2 == 1)
|
||||
{
|
||||
diffX = _mapTileSize.width/2;
|
||||
}
|
||||
return Vec2(pos.x * _mapTileSize.width + diffX,
|
||||
(_layerSize.height - pos.y - 1) * _mapTileSize.height/2);
|
||||
}
|
||||
|
||||
int TMXLayer::getVertexZForPos(const Vec2& pos)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -681,6 +706,9 @@ int TMXLayer::getVertexZForPos(const Vec2& pos)
|
|||
case TMXOrientationOrtho:
|
||||
ret = static_cast<int>(-(_layerSize.height-pos.y));
|
||||
break;
|
||||
case TMXOrientationStaggered:
|
||||
ret = static_cast<int>(-(_layerSize.height-pos.y));
|
||||
break;
|
||||
case TMXOrientationHex:
|
||||
CCASSERT(0, "TMX Hexa zOrder not supported");
|
||||
break;
|
||||
|
|
|
@ -194,7 +194,7 @@ private:
|
|||
Vec2 getPositionForIsoAt(const Vec2& pos);
|
||||
Vec2 getPositionForOrthoAt(const Vec2& pos);
|
||||
Vec2 getPositionForHexAt(const Vec2& pos);
|
||||
|
||||
Vec2 getPositionForStaggeredAt(const Vec2& pos);
|
||||
Vec2 calculateLayerOffset(const Vec2& offset);
|
||||
|
||||
/* optimization methods */
|
||||
|
|
|
@ -54,6 +54,9 @@ enum
|
|||
|
||||
/** Isometric orientation */
|
||||
TMXOrientationIso,
|
||||
|
||||
/** Isometric staggered orientation*/
|
||||
TMXOrientationStaggered,
|
||||
};
|
||||
|
||||
/** @brief TMXTiledMap knows how to parse and render a TMX map.
|
||||
|
|
|
@ -233,6 +233,8 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
tmxMapInfo->setOrientation(TMXOrientationIso);
|
||||
else if(orientationStr == "hexagonal")
|
||||
tmxMapInfo->setOrientation(TMXOrientationHex);
|
||||
else if(orientationStr == "staggered")
|
||||
tmxMapInfo->setOrientation(TMXOrientationStaggered);
|
||||
else
|
||||
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", tmxMapInfo->getOrientation());
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ static int sceneIdx = -1;
|
|||
static std::function<Layer*()> createFunctions[] = {
|
||||
CLN(TMXIsoZorder),
|
||||
CLN(TMXOrthoZorder),
|
||||
CLN(TMXStaggeredTest),
|
||||
CLN(TMXIsoVertexZ),
|
||||
CLN(TMXOrthoVertexZ),
|
||||
CLN(TMXOrthoTest),
|
||||
|
@ -318,6 +319,33 @@ std::string TMXOrthoTest::title() const
|
|||
return "TMX Orthogonal test";
|
||||
}
|
||||
|
||||
TMXStaggeredTest::TMXStaggeredTest()
|
||||
{
|
||||
|
||||
auto map = TMXTiledMap::create("TileMaps/test-staggered.tmx");
|
||||
|
||||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
}
|
||||
|
||||
void TMXStaggeredTest::onEnter()
|
||||
{
|
||||
TileDemo::onEnter();
|
||||
|
||||
Director::getInstance()->setProjection(Director::Projection::_3D);
|
||||
}
|
||||
|
||||
void TMXStaggeredTest::onExit()
|
||||
{
|
||||
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
||||
TileDemo::onExit();
|
||||
}
|
||||
|
||||
std::string TMXStaggeredTest::title() const
|
||||
{
|
||||
return "TMX Staggered test";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TMXOrthoTest2
|
||||
|
|
|
@ -48,6 +48,16 @@ public:
|
|||
virtual void onExit() override;
|
||||
};
|
||||
|
||||
class TMXStaggeredTest : public TileDemo
|
||||
{
|
||||
public:
|
||||
TMXStaggeredTest(void);
|
||||
virtual std::string title() const override;
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
};
|
||||
|
||||
class TMXOrthoTest2 : public TileDemo
|
||||
{
|
||||
public:
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.0" orientation="staggered" width="3" height="3" tilewidth="127" tileheight="97">
|
||||
<tileset firstgid="1" name="grass" tilewidth="127" tileheight="97">
|
||||
<image source="grass.png" width="127" height="97"/>
|
||||
</tileset>
|
||||
<tileset firstgid="2" name="grass01" tilewidth="127" tileheight="97">
|
||||
<image source="grass01.png" width="127" height="97"/>
|
||||
</tileset>
|
||||
<layer name="块层 1" width="3" height="3">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjZGBgYCSAAQDYAAo=
|
||||
</data>
|
||||
</layer>
|
||||
<layer name="块层 2" width="3" height="3">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eJxjYEAAJiSMDAAAnAAH
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
Loading…
Reference in New Issue