0

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;

如果我使用 directyltileMap->setScale()而不是扩展名,那么如果我将图块尺寸乘以当前地图比例量,上面的代码就可以工作。我会用它来代替,CCLayerPanZoom但如果没有这个扩展,我就无法进行平滑和漂亮的缩放。

任何建议如何使它工作?

4

1 回答 1

1

就这样做..

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


convertToNodeSpace method will handle any changes like position or scaling to layer
于 2013-11-22T06:56:37.890 回答