在 libgdx 中管理桌面和设备版本之间的资产 [英] Managing assets between desktop and device version in libgdx

查看:23
本文介绍了在 libgdx 中管理桌面和设备版本之间的资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 libgdx 构建一个小 Android 游戏.现在,我在桌面项目文件夹和 Android 项目文件夹中有游戏资产的副本.出于某种奇怪的原因,我必须在两个版本中以不同的方式访问这些文件.

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.

这在桌面应用程序中工作正常,但在 android 应用程序中给了我一个 FileNotFound 异常:

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"));

如果我从文件名中删除资产",则相反(Android 工作正常,桌面崩溃):

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"));

我不确定问题是什么.两个项目的文件夹结构完全相同......使用 libgdx 的正确方法是什么?

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?

推荐答案

您应该将所有资产存储在 Android 资产文件夹中,并将您的桌面项目链接到该文件夹​​.http://www.badlogicgames.com/wordpress/?p=1537

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

官方项目设置教程也描述了如何执行此操作.它位于 http://code.google.com/p/libgdx/wiki/ProjectSetup#Asset_folder_setup

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.

这篇关于在 libgdx 中管理桌面和设备版本之间的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆