Size mapSize = m_map->getMapSize();
Size tileSize = m_map->getTileSize();
Vec2 pos = position;
float halfMapWidth = mapSize.width * 0.5f;
float mapHeight = mapSize.height;
float tileWidth = tileSize.width;
float tileHeight = tileSize.height;
Vec2 tilePosDiv = CCPointMake(pos.x / tileWidth, pos.y / tileHeight);
float inverseTileY = mapHeight - tilePosDiv.y;
// Cast to int makes sure that result is in whole numbers, tile coordinates will be used as array indices
float posX = (int)(inverseTileY + tilePosDiv.x - halfMapWidth);
float posY = (int)(inverseTileY - tilePosDiv.x + halfMapWidth);
// make sure coordinates are within isomap bounds
posX = MAX(0, posX);
posX = MIN(mapSize.width - 1, posX);
posY = MAX(0, posY);
posY = MIN(mapSize.height - 1, posY);
pos = CCPointMake(posX, posY);
Size tileSize = m_map->getTileSize();
Vec2 pos = position;
float halfMapWidth = mapSize.width * 0.5f;
float mapHeight = mapSize.height;
float tileWidth = tileSize.width;
float tileHeight = tileSize.height;
Vec2 tilePosDiv = CCPointMake(pos.x / tileWidth, pos.y / tileHeight);
float inverseTileY = mapHeight - tilePosDiv.y;
// Cast to int makes sure that result is in whole numbers, tile coordinates will be used as array indices
float posX = (int)(inverseTileY + tilePosDiv.x - halfMapWidth);
float posY = (int)(inverseTileY - tilePosDiv.x + halfMapWidth);
// make sure coordinates are within isomap bounds
posX = MAX(0, posX);
posX = MIN(mapSize.width - 1, posX);
posY = MAX(0, posY);
posY = MIN(mapSize.height - 1, posY);
pos = CCPointMake(posX, posY);