1
votes

I been stuck on this issue for a few days now. I am hoping you guys can help me. I am creating a simple game following this tutorial: http://discuss.cocos2d-x.org/t/tutorial-series-use-the-cocos2d-x-3-0-game-engine-write-a-tile-map-game-part02/12991

and I got stuck on the collision detection part. The method getTileGIDAt() is ALWAYS returning 0, most likely I have found out that this is a Tiled related problem (maybe the tiles are not there, etc), but the problem is that the tiles are completely fine. Everything runs and loads smoothly, with this exception.

Thanks!

here is the code:

void HelloWorld::setPlayerPosition(Point position)
{
    Point tileCoord = this->tileCoordForPosition(position);
    int tileGid = _blockage->getTileGIDAt(tileCoord);
    if (tileGid) {
        auto properties = _tileMap->getPropertiesForGID(tileGid).asValueMap();
        if (!properties.empty()) {
            auto collision = properties["Blockage"].asString();
            if ("True" == collision) {
                return;
            }
        }
    }
    _player->setPosition(position);
}
1
Hey, I have the same problem, do you have any solution? - Anton Shkurenko

1 Answers

0
votes

I would try this tutorial and see how your code matches. I guess the main thing is to check that you have Tiled setup correctly for the different layers.

http://www.raywenderlich.com/29458/how-to-make-a-tile-based-game-with-cocos2d-2-x