LibGDX没有采用Android资源文件夹 [英] LibGDX not using Android asset folder

查看:177
本文介绍了LibGDX没有采用Android资源文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个libGDX项目编译Android或IOS版本在读取资产文件夹有问题。虽然试图android的模块下访问一个文件中的资产文件夹中,我似乎总是得到IOS或Android出现FileNotFoundException,而不是在桌面上运行它时。我的台式机的配置点像它应该是Android资产目录。

在执行以下code:

 公共无效readGameMap()抛出IOException异常
    {
        readGameMap(gameMap.txt);
    }

    公共无效readGameMap(字符串路径)抛出IOException异常
    {

        扫描器S =新扫描仪(Gdx.files.internal(路径).file());


        INT I = 0;


        而((s.hasNextLine()))
        {

            字符串str = s.nextLine();

            如果(str.length()&其中; maze.length)
                抛出新的IOException异常(不正确的game_map.txt结构);

            对于(INT J = 0; J< str.length(); J ++)
            {

                对象温度;

                开关(str.charAt(J))
                {
                    情况1':
                        临时=新墙();
                        打破;

                    案3:
                        临时=新的点();
                        打破;

                    默认:
                        临时=新的对象();
                        打破;
                }

                迷宫[J] [我] =气温;

            }

            我++;
        }

        S.CLOSE();

    }
 

文件没有找到异常。我的文件夹结构如下:

  -Android
  -资产
    -gameMap.txt
-桌面
-IOS
-HTML
-核心
 

解决方案

在情况下,如果你使用的是Android Studio中,选择编辑配置...

更改桌面应用程序 - >工作目录到你的android资产forlder

I am having a problem with a libGDX project reading the assets folder when compiling the Android or IOS build. While trying to access a file in the assets folder under the android module, I always seem to get a FileNotFoundException in IOS or Android, but not when running it on the Desktop. My desktop config points the android asset directory like it should.

When executing the following code :

 public void readGameMap() throws IOException
    {
        readGameMap("gameMap.txt");
    }

    public void readGameMap(String path) throws IOException
    {

        Scanner s = new Scanner(Gdx.files.internal(path).file());


        int i = 0;


        while ((s.hasNextLine()))
        {

            String str = s.nextLine();

            if (str.length() < maze.length)
                throw new IOException("Incorrect game_map.txt structure");

            for (int j = 0; j < str.length(); j++)
            {

                Object temp;

                switch (str.charAt(j))
                {
                    case '1':
                        temp = new Wall();
                        break;

                    case '3':
                        temp = new Dot();
                        break;

                    default:
                        temp = new Object();
                        break;
                }

                maze[j][i] = temp;

            }

            i++;
        }

        s.close();

    }

The file not found exception is thrown. My folder structure is as follows:

-Android
  -assets
    -gameMap.txt
-Desktop
-IOS
-HTML
-core

解决方案

In case if you are using Android Studio, select edit config...

Change 'Desktop Application' -> 'Working Directory' to your android asset forlder

这篇关于LibGDX没有采用Android资源文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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