[英]Adding “Monsters” to a TileMap - LIBGDX
Thanks to alot of help from diff people willing to kindly share their help I have been able to read tilemaps and add my player start to the tilemap 感谢很多人愿意亲切地分享他们的帮助,我已经能够阅读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);
However I would like to also place my monsters on the tilemap like the player, with the exception of i have multiple places on the tilemap to spawn monsters. 但是我想把我的怪物放在像玩家一样的瓷砖地图上,除了我在瓷砖地图上有多个地方来产生怪物。 The below code will only allow me to spawn one monster
下面的代码只允许我产生一个怪物
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);
How could I spawn multiple monsters instead of one? 我怎么能产生多个怪物而不是一个呢? Thank you in advance!
先感谢您!
Have a list of Monsters 有一个怪物列表
Array<Monster> monsters = new Array<Monster> //libgdx Array
And instead of this: 而不是这个:
monsters.position.set(x,y); //wrong!
add a new monster: 添加一个新的怪物:
monsters.add(new Monster(x, y)); //right!
Of course, use the parameters x and y in your monster contructor to set its position. 当然,使用怪物构造函数中的参数x和y来设置其位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.