【发布时间】:2014-10-23 09:48:04
【问题描述】:
我有 3 个图块,我正在尝试为图块地图渲染它们。到目前为止我的代码:public void
render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
int w;
w = 120;
int h;
h = 1080/16;
int tileX = 0;
int tileY = 0;
Texture currentTile = null;
for(int i=0; i<w; i++){
for(int j=0; j<h; j++){
switch(MathUtils.random(2)){
case 0:
currentTile = grass;
tiles.add(grass);
break;
case 1:
currentTile = stone;
break;
case 2:
currentTile = dirt;
break;
}
game.batch.draw(currentTile, i*120, j*120);
}
}
问题在于它渲染得很好,除了瓷砖不断闪烁 - 我认为它们不断被重新渲染。但是我怎么能阻止这是使用二维数组的唯一方法,如果是这样,请展示如何:
渲染数组,在这种格式下我会放什么而不是 currentTile?:
game.batch.draw(currentTile, i*120, j*120);
设置数组,它应该是什么样子,这个?:
Texture[] tiles = new Texture[1];
如何正确地添加图块和构造数组,任何其他细节都会很有用。
【问题讨论】: