我已将 JavaScript spritesheet 转换为 2D 整数数组,现在我正在尝试将 2D 整数数组拆分为多个 2D 数组,使用 1 作为“分隔符”数字。
有没有办法使用分隔符将如下所示的 2D JavaScript 数组分隔为多个数组,如下所示?
function separate2DArray(arrToSeparate, separator){
//separate the 2D array into multiple 2D arrays, using a
//specific number as the separator
}
//array to separate:
[
[5, 5, 5, 1, 5, 4, 5],
[5, 5, 4, 1, 4, 3, 4],
[1, 1, 1, 1, 1, 1, 1], //1 is the "separator number", which splits the array
[9, 2, 1, 4, 2, 4, 5], //horizontally and vertically
]
//The array above would produce the following 2D arrays:
5 5 5
5 5 4
5 4 5
4 3 4
9 2
4 2 4 5
我想到的这个算法的主要应用是 spritesheet 图像分离。