public void fillWith(TileEntity tile){
for(int i = 0; i < this.height; i++){//for every x and y value
for(int j = 0; j < this.width; j++){
tile.x = j;
tile.y = i;
this.tiles.add(tile);
}
}
}
Run Code Online (Sandbox Code Playgroud)
好的,所以上面的代码应该用TileEntity tile填充关卡.当我在"this.tiles.add(tile)"行之前打印x和y coords时,每个tile都有不同的coords.但是当我打印出ArrayList"tiles"中所有tile的x和y坐标时,每一个都是(9,9).它们都与添加到arraylist的最后一个tile相同.谢谢!