【问题标题】:Cocos2D - Collision detection getTileGIDAtCocos2D - 碰撞检测 getTileGIDAt
【发布时间】:2015-12-22 02:25:46
【问题描述】:

我已经被这个问题困扰了几天了。我希望你们能帮助我。我正在按照本教程创建一个简单的游戏:http://discuss.cocos2d-x.org/t/tutorial-series-use-the-cocos2d-x-3-0-game-engine-write-a-tile-map-game-part02/12991

我在碰撞检测部分卡住了。 getTileGIDAt() 方法总是返回 0,很可能我发现这是一个与 Tiled 相关的问题(也许瓷砖不存在等),但问题是瓷砖完全没问题。除了这个例外,一切都可以顺利运行和加载。

谢谢!

代码如下:

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);
}

【问题讨论】:

标签: cocos2d-iphone cocos2d-x tiled


【解决方案1】:

我会试试这个教程,看看你的代码是如何匹配的。我想主要是检查您是否为不同的图层正确设置了 Tiled。

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

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多