Managing assets between desktop and device version in libgdx

Boris picture Boris · Mar 27, 2012 · Viewed 16.5k times · Source

I'm building a little Android game using libgdx. For now I have a copy of the game's assets in the desktop project folder and the Android project folder. For some strange reason I have to access those files differently in each of the two versions.

This works fine in the desktop app but gives me a FileNotFound exception in the android app:

Texture texture = new Texture(Gdx.files.internal("assets/someImage.png"));

If I remove the "assets" from the filename it's the other way round (Android works, desktop crashes):

Texture texture = new Texture(Gdx.files.internal("someImage.png"));

I'm not sure what the problem is. The folder structure is exactly the same for both projects... What is the right way to this with libgdx?

Answer

Deano picture Deano · Mar 27, 2012

You should be storing all of your assets in the Android assets folder and linking your desktop project to that folder. There is a quick description of this at http://www.badlogicgames.com/wordpress/?p=1537

EDIT: The official Project Setup tutorial describes how to perform this as well. It's found at http://code.google.com/p/libgdx/wiki/ProjectSetup#Asset_folder_setup

Aside from project setup I believe that your second method is the correct way of referencing the assets from both projects. After you fix your setup it should work properly in both environments.