ios上的libgdx GdxRuntimeException无法加载文件

我决定把我的应用程序从Android移动到iOS。 应用程序使用libgdx库。 我使用libgdx生成了ios子项目,并使用Xamarin Studio将其打开。 所有图像都从my-project-android / assets / data链接。 所有的图像都设置了构build操作>内容。 现在,每当从Xamarin工作室运行项目,我得到GdxRuntimeException Coldn't加载文件:data / background.png。 这个文件是我在我的应用程序中加载的第一个图像。

我所有的操作,我已经在我的Mac模拟器和iPhone设备上完成。

堆栈跟踪:

com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: /data/background.png ---> System.Exception: unknown protocol: file at java.net.URL..ctor (java.net.URL context, System.String spec, java.net.URLStreamHandler handler) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at com.badlogic.gdx.graphics.Pixmap..ctor (com.badlogic.gdx.files.FileHandle file) [0x0004c] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/Pixmap.java:140 at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare () [0x00052] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/glutils/FileTextureData.java:64 at com.badlogic.gdx.graphics.Texture.load (TextureData data) [0x00036] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/Texture.java:175 at com.badlogic.gdx.graphics.Texture.create (TextureData data) [0x0000d] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/Texture.java:159 at com.badlogic.gdx.graphics.Texture..ctor (com.badlogic.gdx.files.FileHandle file, com.badlogic.gdx.graphics.Format format, Boolean useMipMaps) [0x00060] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/Texture.java:133 at com.badlogic.gdx.graphics.Texture..ctor (com.badlogic.gdx.files.FileHandle file) [0x00001] in /Users/badlogic/jenkins/workspace/libgdx-mac/gdx/src/com/badlogic/gdx/graphics/Texture.java:122 at com.kaproel.trafficControlManager.MainMenuScreen..ctor (com.kaproel.trafficControlManager.trafficControl game) [0x00088] in /Users/Piotr/Developer/mono-iOS/trafficControl/src/com/kaproel/trafficControlManager/MainMenuScreen.java:64 at com.kaproel.trafficControlManager.trafficControl.create () [0x00024] in /Users/Piotr/Developer/mono-iOS/trafficControl/src/com/kaproel/trafficControlManager/trafficControl.java:32 at com.badlogic.gdx.backends.ios.IOSGraphics.OnLoad (System.EventArgs arg0) [0x00010] in /Users/badlogic/jenkins/workspace/libgdx-mac/backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSGraphics.java:133 at OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunWithFrameInterval (Int32 frameInterval) [0x00041] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:694 at OpenTK.Platform.iPhoneOS.iPhoneOSGameView.Run () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/OpenGLES/OpenTK_1.0/Platform/iPhoneOS/iPhoneOSGameView.cs:652 at com.badlogic.gdx.backends.ios.IOSApplication.FinishedLaunching (MonoTouch.UIKit.UIApplication uiApp, MonoTouch.Foundation.NSDictionary options) [0x0023e] in /Users/badlogic/jenkins/workspace/libgdx-mac/backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSApplication.java:166 at 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.kaproel.trafficControlManager.Application.Main (System.String[] args) [0x00000] in /Users/Piotr/Developer/mono-iOS/trafficControl-ios/Main.cs:33 

请给我同样的想法解决scheme

代码狙击:

  public MainMenuScreen(final trafficControl game) { this.game = game; this.stage = new Stage(0, 0,true); batch = new SpriteBatch(); this.camera = new OrthographicCamera(); this.camera.setToOrtho(false, 800, 480); texture = new Texture(Gdx.files.local("data/background.png")); // <!-- this line make runtime error 

它可能是一个优化问题。 你有没有检查这个链接

http://code.google.com/p/libgdx/wiki/IOSWIP

阅读此页面中的PNG优化。 可能会帮助你。