簡體   English   中英

將“怪物”添加到TileMap - LIBGDX

[英]Adding “Monsters” to a TileMap - LIBGDX

感謝很多人願意親切地分享他們的幫助,我已經能夠閱讀tilemaps並將我的播放器開始添加到tilemap

for (int x = 0; x < layer3.getWidth(); x++) {
    for (int y = 0; y < layer3.getHeight(); y++) {
        TiledMapTileLayer.Cell cell = layer3.getCell(x, y);
        if (cell == null)
            continue;
        if (cell.getTile() == null)
            continue;
        if (cell != null) {
            TiledMapTile tile = cell.getTile();
            if (tile != null) {
                if (layer3.getCell(x, y).getTile().getProperties()
                            .containsKey("Start"))
                            player.position.set(x, y);     

但是我想把我的怪物放在像玩家一樣的瓷磚地圖上,除了我在瓷磚地圖上有多個地方來產生怪物。 下面的代碼只允許我產生一個怪物

for (int x = 0; x < layer2.getWidth(); x++) {
    for (int y = 0; y < layer2.getHeight(); y++) {
        TiledMapTileLayer.Cell cell = layer2.getCell(x, y);
        if (cell == null)
            continue;
        if (cell.getTile() == null)
            continue;
        if (cell != null) {
            TiledMapTile tile = cell.getTile();
            if (tile != null) {
                if (layer2.getCell(x, y).getTile().getProperties()
                        .containsKey("monster"))
                        monsters.position.set(x,y);

我怎么能產生多個怪物而不是一個呢? 先感謝您!

有一個怪物列表

Array<Monster> monsters = new Array<Monster> //libgdx Array

而不是這個:

monsters.position.set(x,y); //wrong!

添加一個新的怪物:

monsters.add(new Monster(x, y)); //right!

當然,使用怪物構造函數中的參數x和y來設置其位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM