【发布时间】:2014-03-05 17:37:31
【问题描述】:
如何创建包含 ArrayLists 的二维数组?像这样的东西:
ArrayList<Character>[][] myArray = new ArrayList<Character>[][];
是否可以执行以下操作:
我需要将某些角色的位置与地图中建筑物的位置进行比较。多个建筑物可以属于同一个图块,但可以在角色前面绘制一个,在他后面绘制另一个。在游戏中,每个角色都必须始终进行这种比较。
每次一个字符从一个磁贴移动到另一个磁贴时,我都会尝试更新一组字符。然后,render 方法应该查找特定图块中有多少字符(如果有),并遍历该图块中的字符以将它们绘制在建筑物的前面或后面。
类似这样的:
//init
ArrayList<Character>[][] arrayOfCharacters = new ArrayList<Character>[][];
//each tile in the map
for (int y = 0; y < 9; y++){
for(int x = 9-1; x >= 0; x--){
if ( arrayOfCharacters[y][x].length > 0 ){
for ( int i=0, i< arrayOfCharacters[y][x].length; i++ ){
//compare which building is in front or behind the characters
//then
characterInThisTile = index of each character in arrayOfCharacters[y][x]
spriteBatch.draw(characterInThisTile, x_pos, y_pos, tileWidth, tileHeight);
}
}
}
}
【问题讨论】:
标签: java arrays arraylist libgdx