Cocos2d x CCLayerPanZoom延伸和等轴测tilemap

Cocos2d x CCLayerPanZoom延伸和等轴测tilemap,cocos2d-x,cclayerpanzoom,Cocos2d X,Cclayerpanzoom,当我使用CCLayerPanZoom扩展时,我在从触摸位置获取瓷砖坐标时遇到问题。它在没有缩放的情况下运行良好(当缩放比例为1.0f),但如果放大或缩小,它会返回奇怪的坐标。这是我的tilePosFromLocation方法: CCPoint pos = ccpSub(location, _panZoomLayer->getPosition()); float halfMapWidth = tileMap->getMapSize().width * 0.5f; float m

当我使用
CCLayerPanZoom
扩展时,我在从触摸位置获取瓷砖坐标时遇到问题。它在没有缩放的情况下运行良好(当缩放比例为
1.0f
),但如果放大或缩小,它会返回奇怪的坐标。这是我的
tilePosFromLocation
方法:

CCPoint pos = ccpSub(location, _panZoomLayer->getPosition());
float halfMapWidth = tileMap->getMapSize().width * 0.5f;    
float mapHeight = tileMap->getMapSize().height;     
float tileWidth = tileMap->getTileSize().width;     
float tileHeight = tileMap->getTileSize().height;   
CCPoint tilePosDiv = CCPointMake(pos.x / tileWidth, pos.y / tileHeight); 
float inverseTileY = mapHeight - tilePosDiv.y;
float posX = (int)(inverseTileY + tilePosDiv.x - halfMapWidth); 
float posY = (int)(inverseTileY - tilePosDiv.x + halfMapWidth);
posX = MAX(0, posX); 
posX = MIN(tileMap->getMapSize().width - 1, posX);  
posY = MAX(0, posY); 
posY = MIN(tileMap->getMapSize().height- 1, posY); 
pos=ccp(posX, posY);
return pos;
如果我使用directyl
tileMap->setScale()
而不是扩展名,那么如果我将平铺尺寸与当前地图比例量相乘,上面的代码就会起作用。我会用它来代替
CCLayerPanZoom
,但如果没有这个扩展,我就无法进行平滑而漂亮的缩放

有什么建议吗?

就这么做吧

location=_panZoomLayer->convertToNodeSpace(location); //location is touchLocation ..after convertToGL


convertToNodeSpace method will handle any changes like position or scaling to layer