I noticed that if you pack 10+ sprites named 0.png (e.g. [0,1,2,3,4,5,6,7,8,9,10,11]) it will list them improperly ([0,1,10,11,2,3,4,5,6,7,8,9]).
Sorting will fix this glitch:
Code:
import java.util.Comparator;
Code:
public static void buildSpriteList() {
Main.log("Building list of image files in the sprites folder...");
int id = 0;
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
int n1 = extractNumber(o1.getName());
int n2 = extractNumber(o2.getName());
return n1 - n2;
}
private int extractNumber(String name) {
int i = 0;
try {
int s = name.indexOf(" ") + 1;
int e = name.lastIndexOf(".png");
String number = name.substring(s, e);
i = Integer.parseInt(number);
} catch (Exception e) {
i = 0; // if filename does not match the format
// then default to 0
}
return i;
}
});
for (File f : files) {
if (f.isDirectory()) {
continue;
}
if (!f.getName().contains(".png")) {
continue;
}
spriteFiles.add(new FileSprite(id, fileToByteArray(f)));
System.out.println(f.getName() + ", " + id);
id++;
}
Main.log("Found " + spriteFiles.size() + " images in the sprites folder!");
}