繁体   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