Alex Rivera | Logout

Managing assets between desktop and device version in libgdx

Asked 2012-03-27T15:44:58.157
10

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?

Edit
Report

2 Answers

0

Check if all of your files are in lower case in android assets folder

answered 2012-07-19T15:26:55.157
0

Referencing the android assets folder is not a really good idea, because:

1) Eclipse will probly take copy your referenced assets folder to the apk of the android project, duplicating the size of 2) paths should be platform agnostics. As I see it, this is a JogFiles implementation issue.

You better copy the folloing class to your classpath:

package com.badlogic.gdx.backends.jogl; /******************************************************************************* * Copyright 2011 See AUTHORS file. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package com.badlogic.gdx.backends.jogl; import java.io.File; import com.badlogic.gdx.Files; import com.badlogic.gdx.files.FileHandle; /** * Gdx class overrided in order to keep internal files paths platform independent. * Android search at "assets/" folder. And so we do here for jogl. */ final class JoglFiles implements Files { private static final String ASSETS_FOLDER = "assets"; private final String externalPath = System.getProperty("user.home") + "/"; @Override public FileHandle getFileHandle (String fileName, FileType type) { return new JoglFileHandle(fileName, type); } @Override public FileHandle classpath (String path) { return new JoglFileHandle(path, FileType.Classpath); } @Override public FileHandle internal (String path) { // append "as
answered 2012-07-26T22:09:34.947

Your Answer