使用AssetManager加载时,在IOS上无法加载TextureAtlas文件,使用libgdx。

3

我正在将我的LIBGDX应用程序移植到IOS。我使用Xamarin studio的libgdx移植版在IOS上运行我的应用程序。我成功地进行了移植,但是应用程序无法在iPhone模拟器中加载TextureAtlas文件和BitmapFont文件。

我尝试的代码是:

   ...
    AssetManager assetManager = new AssetManager();
    assetManager.load("packer/help.txt", TextureAtlas.class);

    if (assetManager.update()) {

    }
    ...

以上代码在我的桌面和安卓设备上运行良好,但在 iPhone 模拟器上运行时,我收到了以下日志。

Unhandled Exception:
0   iosgame                             0x000f4f7e mono_handle_exception_internal_first_pass + 2190
1   iosgame                             0x000f69c2 mono_handle_exception_internal + 1602
2   iosgame                             0x000f750f mono_handle_exception + 47
3   iosgame                             0x0013a662 mono_x86_throw_exception + 306
4   ???                                 0x0b730f8f 0x0 + 192089999
at com.badlogic.gdx.assets.AssetManager.update () [0x0009c] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:346
at (wrapper synchronized) com.badlogic.gdx.assets.AssetManager.update () <IL 0x00009, 0x0002c>
at com.racing.gold.Screen.SplashScreen.update (single) [0x0001f] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Screen/SplashScreen.java:80
at com.racing.gold.Game.render () [0x0000d] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Game.java:48

at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x00056, 0x000a4>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at com.ios.temp.project.Application.Main (string[]) [0x00000] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game-ios/Main.cs:33
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00049, 0x00077>
30  iosgame                             0x0006f462 mono_jit_runtime_invoke + 722
31  iosgame                             0x001d34de mono_runtime_invoke + 126
32  iosgame                             0x001d76d4 mono_runtime_exec_main + 420
33  iosgame                             0x001dcac5 mono_runtime_run_main + 725
34  iosgame                             0x000ccb65 mono_jit_exec + 149
35  iosgame                             0x0026b494 main + 1988
36  iosgame                             0x00068269 start + 53

2013-06-11 09:51:47.694 iosgame[567:c07] Unhandled managed exception: java.net.MalformedURLException: unknown protocol: file (com.badlogic.gdx.utils.GdxRuntimeException)
  at com.badlogic.gdx.assets.AssetManager.handleTaskError (System.Exception t) [0x000bf] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:512 
  at com.badlogic.gdx.assets.AssetManager.update () [0x0009c] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src//com/badlogic/gdx/assets/AssetManager.java:346 
  at (wrapper synchronized) com.badlogic.gdx.assets.AssetManager:update ()
  at com.racing.gold.Screen.SplashScreen.update (Single deltaTime) [0x0001f] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Screen/SplashScreen.java:80 
  at com.racing.gold.Game.render () [0x0000d] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game/src/com/racing/gold/Game.java:48 
  at com.badlogic.gdx.backends.ios.IOSGraphics.OnRenderFrame (OpenTK.FrameEventArgs arg0) [0x00184] in /Users/badlogic/jenkins/workspace/libgdx-mac/backends/gdx-backend-iosmonotouch/src//com/badlogic/gdx/backends/ios/IOSGraphics.java:185 
  at OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000c1] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:830 
  at OpenTK.Platform.iPhoneOS.CADisplayLinkTimeSource.RunIteration () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:158 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at com.ios.temp.project.Application.Main (System.String[] args) [0x00000] in /Users/Vikalp/Downloads/libgdx-nightly-20130609/Generated Project/my-gdx-game-ios/Main.cs:33 

我试图将我的包扩展名从.txt更改为.pack,但输出结果相同。

我在Libgdx论坛上没有找到解决方案。请帮我解决这个问题。


相关链接:https://dev59.com/KW3Xa4cB1Zd3GeqPk_wF - P.T.
2个回答

4

嘿,我找到了问题。

当我们从Xamarin Studio运行应用程序时,它并没有将所有的项目都打包进去。一些文件,如文本文件、xml等被留下了。我们需要将它们标记为需要包含在应用程序中。将所有这些文件标记为要添加的Bundle资源。


你应该接受自己的答案作为“解决方案”,因为你找出了问题。 - jstedfast

0

根据Badlogic论坛上的此帖子,可能有几件事情出了问题:

  • 您正在使用java.net API(可能不适用于您的情况)
  • 您正在使用Gdx.files.classpath来加载某些文件
  • 您没有完全/正确地将资产打包到构建中。

仔细阅读Libgdx IOSWiki以了解注意事项并确保已正确设置所有内容。

这个(类似的)问题:libgdx on ios GdxRuntimeException couldn't load file 之所以得到解决,是因为PNG文件没有正确地进行优化。请参考“PNG优化”部分(特别注意您使用的Libgdx版本,因为它似乎已经改变了行为)。

根据上述相关链接,我已经检查了所有的设置步骤。当我直接加载纹理并使用它们来查找纹理区域时,它可以正常工作并在模拟器上运行,但是这样创建它们非常繁琐。我在通过纹理图集加载时遇到了问题。同时,在运行应用程序时,我已经注意到了“PNG优化”。 - Vikalp Jain

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接