From e33baac3964a4fcd1a89de2d7381ca587dc42083 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 6 Feb 2014 22:20:28 -0800 Subject: [PATCH] iso almost working --- cocos/2d/CCTMXLayer2.cpp | 22 +++++++++++++------ .../Classes/TileMapTest/TileMapTest.cpp | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cocos/2d/CCTMXLayer2.cpp b/cocos/2d/CCTMXLayer2.cpp index ae8239c308..af2ea04ca1 100644 --- a/cocos/2d/CCTMXLayer2.cpp +++ b/cocos/2d/CCTMXLayer2.cpp @@ -240,28 +240,34 @@ int TMXLayer2::getTileIndex(int x, int y, cocos2d::Point baseTile) switch (_layerOrientation) { case TMXOrientationOrtho: - if( baseTile.x + x < 0 || baseTile.x + x >= _layerSize.width - || baseTile.y + y < 0 || baseTile.y + y >= _layerSize.height) + x += baseTile.x; + y += baseTile.y; + + if( x < 0 || x >= _layerSize.width + || y < 0 || y >= _layerSize.height) tileidx = -1; else - tileidx = (_layerSize.height - (baseTile.y + y) - 1) * _layerSize.width + baseTile.x + x; + tileidx = (_layerSize.height - y - 1) * _layerSize.width + x; break; case TMXOrientationIso: - x += baseTile.x; - y -= baseTile.y*2 + 1; - int xx = x + (y-1) / 2; - int yy = y/2 - x; + x += baseTile.x; + y -= baseTile.y*2; + + int xx = x + y/2; + int yy = (y+1)/2 - x; if( xx < 0 || xx >= _layerSize.width || yy < 0 || yy >= _layerSize.height ) tileidx = -1; else tileidx = xx + _layerSize.width * yy; + break; } + return tileidx; } @@ -405,6 +411,8 @@ void TMXLayer2::setupTiles() case TMXOrientationIso: _screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 2; _screenGridSize.height = ceil(screenSize.height / (_mapTileSize.height/2)) + 4; +// _screenGridSize.width = 3; +// _screenGridSize.height = 4; break; case TMXOrientationHex: break; diff --git a/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp b/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp index 962c457a41..3e6871a45d 100644 --- a/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp +++ b/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp @@ -284,9 +284,9 @@ TMXOrthoTest::TMXOrthoTest() //addChild(color, -1); // riq -// auto map = TMXTiledMap2::create("TileMaps/iso-test1.tmx"); + auto map = TMXTiledMap2::create("TileMaps/iso-test1.tmx"); // auto map = TMXTiledMap2::create("TileMaps/orthogonal-test2.tmx"); - auto map = TMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx"); +// auto map = TMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx"); addChild(map, 0, kTagTileMap);