我在点击事件里面添加一个getTileAt(),想确认一下每个格子的tag是多少,结果,没点击一次,地图就乱一次,详情看图片。
代码在这:
bool MyTileMap::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event)
{
if(!_pressingSpaceBar)
{
Point pos = _map->convertTouchToNodeSpaceAR(touch);
auto tileLayer = _map->getLayer("Tile Layer 1");
if(tileLayer)
{
Point tileLocation(pos.x / _map->getTileSize().width, pos.y / _map->getTileSize().height);
if(tileLocation.x > 0.0f && tileLocation.y > 0.0f && tileLocation.x < _map->getMapSize().width && tileLocation.y < _map->getMapSize().height)
{
auto tile = tileLayer->getTileAt(tileLocation);
if(tile)
{
CCLOG("Current Click Tile Tag : %d", tile->getTag());
}
}
}
}
return true;
}
```
不知道各位有没有出现这种问题