1
for(Rectangle tile: tiles) {
    if(koalaRect.overlaps(tile)) {
        // we actually reset the koala y-position here
        // so it is just near the tile we collided with
        // this removes bouncing :)
        if(koala.velocity.y > 0) {
            koala.position.y = tile.y - Koala.HEIGHT;
            // we hit a block jumping upwards, let's destroy it!
            TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
            layer.setCell((int)tile.x, (int)tile.y, null);
        } else {
            koala.position.y = tile.y + tile.height;
            // if we hit the ground, mark us as grounded so we can jump
            koala.grounded = true;
        }
        koala.velocity.y = 0;
        break;
    }
}

このコードはスーパーコアラのものです。

私が欲しいのは、コアラ/ヒーローが壁/タイルに衝突したときにタイルをチェックすることです。次に、タイルを3つのフォームに変更したいと思います。固いタイル、少しひびの入ったタイル、非常に壊れやすいタイルを最終的に破壊します。

switch(layer){
"SolidLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(3);
//get cracked tile
layer.setCell((int)tile.x, (int)tile.y, null);
"CrackLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(2);
//get fragile tile
layer.setCell((int)tile.x, (int)tile.y, null);
"FragileLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
//get destroyed layer
layer.setCell((int)tile.x, (int)tile.y, null);}

これは可能ですか?

4

2 に答える 2

0

セルを null に設定する代わりに、そのスペースを占有する新しいタイルに設定します (前のタイルがソリッドの場合はクラックに設定し、クラックの場合は null に設定します)。そうすれば、複数のレイヤーは必要ありません。

このようなもの。

TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
TiledMapTileLayer.Cell cell = layer.getCell((int)tile.x, (int)tile.y);
TiledMapTile tile = cell != null ? cell.getTile() : null;
if (tile != null) {
    switch (tile.getId()) {
    case TILE_SOLID:
        cell.setTile(crackedTile);
        break;
    case TILE_CRACKED:
        cell.setTile(null);
        break;
    }
}
于 2013-07-03T16:17:49.447 に答える