Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...