How to get Tile Coordinate from Touch Location?

How to get Tile Coordinate from Touch Location?
0.0 0


Dear community,

This is my first post in this forum, so be soft to me :slight_smile:
Now, I have spent several hours in my tiled base game trying to detect which tile being touch by user.

These are my test code, I kinda hoping that the last line, getPositionAt(), will give me the tile coordinate, but that’s not it. Any suggestion?

void HelloWorld::onTouchesBegan(const std::vector& touches, Event* event)
    Touch* touch = touches[0];
    Point location = touch->getLocationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    location = this->convertToNodeSpace(location);
    location = tileMap->getLayer("one")->getPositionAt(location);
    log("getPositionAt  x:%f, y:%f", location.x, location.y);

I have already read on several Q&A in this forum that close to what I asked, but still unable to implement it in my code.

Any help will be appreciated!