Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

android - Managing assets between desktop and device version in libgdx

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...