Hi, I recently added 402 (256x256pixel) PNG images into my game that are loaded right away. This causes my game to take around 1737ms to load, or 1.737 seconds. I tried to add a loading screen in the begging so the user doesn’t just see a black screen for 1.737 seconds (which is bound to get longer in the future). However, upon adding a loading screen it causes the game to take around 7435ms, or 7.435 seconds to load.
I noticed that “Display.update();” is what causes the increase in time spent but without that function I can not draw the display bar. The API states that update() does the following “Update the window. If the window is visible clears the dirty flag and calls swapBuffers() and finally polls the input devices.” Getting rid of input only added a few milliseconds and I am not exactly sure what dirty flags and swapBuffers() do, perhaps that is what causes the delay.
Here is the function used.
public void initSkillIconTextures(String path) throws IOException {
Mouse.destroy();
Keyboard.destroy();
Scanner scanner = null;
try {
scanner = new Scanner(new FileInputStream(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
// While the text file still has another image name, continue reading image names, storing the Textures into an ArrayList<Texture>
while (scanner.hasNextLine()) {
skillIcons.add(TextureLoader.getTexture(
"PNG",
ResourceLoader.getResourceAsStream("res" + File.separatorChar + "images" + File.separatorChar + "spell_Icons" + File.separatorChar
+ scanner.nextLine())));
// loadingRender() draws the loading bar but removing this method only got rid of a few milliseconds.
loadingRender();
Display.update();
}
} finally {
try {
Mouse.create();
Keyboard.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
LOADING = false;
scanner.close();
}
}
Perhaps I should create a JFrame to display the status of loading; or maybe I am approaching the whole situation incorrectly? If someone could point me in the right direction it would be very helpful.
Thank you for your time.