3

我开始将我的 LIBGDX 应用程序移植到 IOS。我使用 libgdx 的 Xamarin studio 端口在 IOS 上运行我的应用程序。我移植成功,但应用程序无法在 Iphone Simulator 中加载 TextureAtlas 文件和 BitmapFont 文件。

我试过的代码是

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

    if (assetManager.update()) {

    }
    ...

上面的代码在桌面和 android 上运行良好,但在 Iphone Simulator 上运行时,我得到了以下日志。

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 论坛上找到解决方案。请赐教这个问题。

4

2 回答 2

4

嘿,我发现了问题。

当我们从 Xamarin Studio 运行应用程序时,它不会打包所有项目。它留下了一些文件,如文本文件、xmls 等。我们需要标记它们以将它们包含在应用程序中。将所有这些文件标记为捆绑资源。

于 2013-06-13T10:56:39.343 回答
0

根据Badlogic 论坛上的这篇帖子,有几件事可能是错误的:

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

仔细阅读Libgdx IOSWiki以了解警告并确保您已正确设置所有内容。

这个(类似的)问题:libgdx on ios GdxRuntimeException could't load file 已解决,因为 PNG 文件未正确优化。请参阅“PNG 优化”部分(并特别注意您正在使用的 Libgdx 版本,因为它的行为似乎已经改变)。

于 2013-06-11T06:40:17.553 回答