【问题标题】:AndEngine change TMX Tiled Map DynamicallyAndEngine 动态改变 TMX Tiled Map
【发布时间】:2015-12-01 19:12:11
【问题描述】:

我已经阅读了这个问题的所有可能重复项,但没有一个能给我一个完整的解决方案(解决方案分为答案),所以我决定尝试解决问题。顺便说一句,StackOverflow 告诉我:

不是您要找的答案?浏览标记为 android andengine tmx 的其他问题或提出您自己的问题。

It's OK to Ask and Answer Your Own Questions
所以[...]如果您想公开记录它,以便其他人(包括您自己)以后可以找到它

现在很清楚了,我想动态更改 TMX 地图。例如,地图有一个箱子对象。玩家在上面行走并获得金币。然后我想从地图上移除箱子,这样玩家就不能多次收集箱子了。我该怎么做?

【问题讨论】:

    标签: java android andengine tmx


    【解决方案1】:

    可以从地图上移除宝箱以使其不再被收集,但不能通过编辑 TMX 地图。为了做到这一点,每当玩家走过一个箱子时(通过向箱子添加一个属性来检查,例如 chest=true 然后检查它),除了奖励玩家之外,您还必须做一些事情,那就是使用共享偏好保存箱子有使用字符串集(例如,使用键“chests”)并包含坐标,用“:”分隔。保存坐标:

    String saveMe = tileRow + ":" + tileColumn;
    removeChest(tileRow, tileColumn);
    

    加载坐标:

    String loaded = loadString();
    String[] coords = loades.split(":");
    tileRow = Integer.parseInt(coords[0]);
    tileColumn = Integer.parseInt(coords[1]);
    removeChest(tileRow, tileColumn);
    

    现在您可以保存/加载使用过的箱子。这是每当玩家走过具有 (chest=true) 属性的图块时:

    boolean found = false;
    for (int i = 0; i < chestsUsedTileRowsArray.length; i++) {
        if (chestFoundTileRow == chestsUsedTileRowsArray[i] && chestFoundTileColumn == chestsUsedTileColumnsArray[i]) {
            found = true;
            break;
        }
    }
    if (!found) {
        rewardPlayer();
        saveChestUsed(tileRow, tileColumn);
    }
    

    最后,removeChest() 需要一个小技巧:在胸部绘制一个具有地面纹理的精灵:

    void removeChest(int tileRow, int tileColumn) {
        final TMXTile tileToReplace = tmxMap.getTMXLayers().get(0).getTMXTile(tileColumn, tileRow);
        final int w = tileToReplace.getTileWidth();
        final int h = tileToReplace.getTileHeight();
        Sprite sprite = new Sprite(w * (tileColumn + 0.5), h * (tileRow + 0.5), textureRegionOfGround, this.getVertexBufferObjectManager());
        scene.addChild(sprite);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 2012-10-29
      • 2014-12-21
      • 2013-03-29
      • 2014-10-03
      • 2013-06-03
      • 2012-08-18
      • 1970-01-01
      • 2014-12-19
      相关资源
      最近更新 更多