渲染二维数组Libgdx的Java [英] Rendering 2D array Libgdx Java
问题描述
我要创建我的游戏随机瓷砖的地图,这是我迄今为止:
I want to create a random tiled map for my game, this is what I have so far:
switch(MathUtils.random(2)){
case 0:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile1, tileX, tileY);
System.out.print("tile1");
currentTile = tile1;
break;
case 1:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile2, tileX, tileY);
System.out.print("tile2");
currentTile = tile2;
break;
case 2:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile3, tileX, tileY);
System.out.print("tile3");
currentTile = tile3;
break;
}
game.batch.begin();
game.batch.draw(currentTile, tileX, tileY);
game.batch.end();
}
而不是单独使他们每个我想将它们添加到一个数组和渲染
他们都在一起,所以如果我有一个数组像这样的:
Instead of rendering them each individually i would like to add them to an array and render them all together, so if i have an array such as this:
ArrayList<Texture> tiles;
然后添加一些东西到所有的情况下,他喜欢的选项:
Then add something to all of he case options like:
tiles.add(tile1);
问题:
我如何渲染阵列,并获得培训相关坐标为他们进行渲染,这是否被添加到阵列?
How do i render the array and get the relevent co-ordinates for them to be rendered, does this get added to the array?
推荐答案
我解决了类似的问题是这样的:
I solved a similar problem like this:
batch.begin();
for (Ground ground : groundArray){
batch.draw(ground.getTextureRegion(), ground.x, ground.y);
}
batch.end();
有关更多信息看<一个href=\"http://gamedev.stackexchange.com/questions/82087/2d-libgdx-runtime-level-generation\">HERE
如果你有一些问题,我会很乐意更新我的答案,只是张贴在注释中。
If you have some questions i will be happy to update my answer, just post in comments.
有你去:
public class Ground {
public float x;
float y;
private TextureRegion texture;
private Rectangle bounds;
public Ground(float x, float y){
texture = Assets.atlas.findRegion("ground");
this.x = x;
this.y = y;
bounds = new Rectangle(x, y, 100, 498);
}
public TextureRegion getTextureRegion(){
return texture;
}
public Rectangle getBounds(){
return bounds;
}
}
如果您想了解Asstes.atlas.findRegions看<一个href=\"http://stackoverflow.com/questions/25305191/using-libgdx-how-do-you-have-an-animation-using-seperate-images/25365653#25365653\">HERE
If you want to know about Asstes.atlas.findRegions look HERE
这篇关于渲染二维数组Libgdx的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!