[LibGDX] Best way to play an animated intro

I need to play a short (5-ish second) intro animation, its 133 frames long, but after removing identical frames there are 92 unique frames remaining. This is how I load them :

	private void loadIntro() {
		if (shouldPlayIntro) {
			introTextures = new Texture[133];
			for (int i = 0; i < 132; i ++) {
				try {
					introTextures[i] = new Texture(Gdx.files.internal("assets/intro/Frame ("+i+").jpg"));
				} catch (GdxRuntimeException e) { }
			}
		}
	}

The way that works is fairly simple :

  • Try to load next frame
  • If you cant, the frame has been cut out because it is identical to the previous frame. Just leave that index null, that image was cut out because it is identical to the previous image

(When rendering, if the next frame to be rendered is null then it will render the previous frame)

You might notice also that I am swallowing a Exception, but it is slower to check to see if a file exists and then load it than load it and swallow the exception. Probably bad practice, but I really need all the performance I can get :frowning:

The problem is that loading these textures takes 1.509 seconds on my laptop (Not too bad, bearable) but a whopping 10.41 seconds on my android tablet (Samsung Galaxy Tab 2)! This makes for a long black screen before playing the intro, and I fear that even with a loading screen that people wont get to play the game because they will think the game is frozen. Also having the loading screen before the intro is not optimal.

How do you guys load an intro and play it? Am I doing it wrong? Should it be taking this long to load?

Find out what the bottleneck is on the tablet, it’s most likely going to be either loading it from file or decompressing the frames. If the CPU is maxed during that black screen, then it’s the compression and you could use less compressed files. If it’s very low, then it’s probably just the IO which can’t be helped much I don’t think, besides using more (or different, more appropriate) compression.

My guess is that’s it’s the decoding/decompression.

May I ask why?

You would rather have a black screen for a short time and then an animation intro, then load your game…?

Why not just load every single thing on a loading screen, then show the intro? After the intro it just fires right to your menu, no more loading.

Just curious.

Well the reason is mostly artistic, the intro video doesn’t match the look/feel of the game and I wanted the loading screen to play into the central theme. Having a loading screen before the intro would mean that I would have to match the loading screen to the intro video, which I personally think would look worse. But whichever way I end up going, the load time is way to long :frowning:

Anyway, right now the files arnt compressed, like at all. Is that the issue? They are just loose .jpg’s in a folder. How would I go about loading a compressed file format?

JPEG is a compressed format, but the level of compression can be varied at encode time. Also JPEG might not be the most appropriate format to use.

Still, you can’t be sure what the problem is and thus how to deal with it until you figure out what the bottleneck is.