AndEngine 加载图形:资产文件夹和资源放在哪里?
AndEngine Loading Graphics: Where Do I put my assets folder and my resources?
在使用 Android Studio 使用 AndEngine 创建游戏时,我将资产文件夹放在项目的根目录下。我还在其下创建了一个名为 gfx 的文件夹,并将我的 splash.png 放在那里。
当我调用启动画面时:
public void loadSplashScreen()
{
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
splashTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 390, 534, TextureOptions.BILINEAR);
splash_region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(splashTextureAtlas, activity, "splash.png", 0, 0);
splashTextureAtlas.load();
}
这是产生的错误
我是不是放错地方了?资产应该放在哪里?
E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:52)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:43)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:86)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:82)
at com.waylonhuang.game.ResourcesManager.loadSplashScreen(ResourcesManager.java:68)
at com.waylonhuang.game.SceneManager.createSplashScene(SceneManager.java:93)
at com.waylonhuang.game.GameActivity.onCreateScene(GameActivity.java:62)
at org.andengine.ui.activity.BaseGameActivity.onCreateResourcesFinished(BaseGameActivity.java:171)
at com.waylonhuang.game.GameActivity.onCreateResources(GameActivity.java:45)
at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:183)
at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:112)
at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:21.329 30718-30749/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:101)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:85)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:154)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:21.348 30718-30749/com.waylonhuang.game W/dalvikvm﹕ threadid=15: thread exiting with uncaught exception (group=0x41717d40)
01-17 16:48:21.349 30718-30749/com.waylonhuang.game E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 6799
Process: com.waylonhuang.game, PID: 30718
org.andengine.util.exception.NullBitmapException: Caused by: class org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource --> AssetBitmapTextureAtlasSource(gfx/splash.png) returned a null Bitmap.
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:156)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:23.282 30718-30749/com.waylonhuang.game I/Process﹕ Sending signal. PID: 30718 SIG: 9
01-17 16:59:01.645 2098-2098/com.waylonhuang.game D/dalvikvm﹕ Late-enabling CheckJNI
01-17 16:59:02.020 2098-2098/com.waylonhuang.game I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8226_LNX.LA.3.5.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/07/14 Fri
Local Branch:
Remote Branch: quic/LNX.LA.3.5.1_RB1.1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING
01-17 16:59:02.052 2098-2098/com.waylonhuang.game D/OpenGLRenderer﹕ Enabling debug mode 0
01-17 16:59:02.087 2098-2119/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:52)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:43)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:86)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:82)
at com.waylonhuang.game.ResourcesManager.loadSplashScreen(ResourcesManager.java:68)
at com.waylonhuang.game.SceneManager.createSplashScene(SceneManager.java:93)
at com.waylonhuang.game.GameActivity.onCreateScene(GameActivity.java:62)
at org.andengine.ui.activity.BaseGameActivity.onCreateResourcesFinished(BaseGameActivity.java:171)
at com.waylonhuang.game.GameActivity.onCreateResources(GameActivity.java:45)
at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:183)
at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:112)
at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:59:02.106 2098-2119/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:101)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:85)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:154)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:59:02.110 2098-2119/com.waylonhuang.game W/dalvikvm﹕ threadid=15: thread exiting with uncaught exception (group=0x41717d40)
01-17 16:59:02.111 2098-2119/com.waylonhuang.game E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 7084
Process: com.waylonhuang.game, PID: 2098
org.andengine.util.exception.NullBitmapException: Caused by: class org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource --> AssetBitmapTextureAtlasSource(gfx/splash.png) returned a null Bitmap.
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:156)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
您必须在路径 app/src/main/ 中创建 "assets" 文件夹,并将带有 splash.png 的 "gfx" 文件夹放入其中
如果您使用的是 Eclipse,您应该直接从 Eclipse 创建 "gfx" 文件夹,然后将 splash.png 图片拖放到该文件夹中,确保您复制出现提示时,文件,而不是 link 它。 链接会产生可访问性问题。
这是我在 eclipse 中的一个小项目的工作项目结构:
这是我的调用方法的样子:
public void loadSplashResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/splash/");
mSplashTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(), 480, 800, TextureOptions.BILINEAR);
mSplashTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mSplashTextureAtlas, mActivity, "splash.png", 0, 0);
mSplashTextureAtlas.load();
mFont1 = FontFactory.create(mActivity.getFontManager(), mActivity.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), 10, Color.GRAY);
mFont1.load();
}
还有一个用于资源优化目的的卸载方法是明智的:
public void unloadSplashResources() {
mSplashTextureAtlas.unload();
mSplashTextureRegion = null;
mFont1.unload();
mFont1 = null;
}
在我的主activity中,然后我在加载资源时调用启动画面的加载:
@Override
protected void onCreateResources() {
mResourceManager = ResourceManager.getInstance();
mResourceManager.prepare(this);
mResourceManager.loadSplashResources();
mSceneManager = SceneManager.getInstance();
}
创建新场景后,我卸载启动画面:
@Override
protected Scene onCreateScene() {
mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
mEngine.unregisterUpdateHandler(pTimerHandler);
mResourceManager.loadGameResources();
mSceneManager.setScene(SceneType.SCENE_MENU);
mResourceManager.unloadSplashResources();
}
}));
希望您可以交叉参考这些样本,看看您的启动画面是否有类似配置的地方,并找到问题的原因。
在使用 Android Studio 使用 AndEngine 创建游戏时,我将资产文件夹放在项目的根目录下。我还在其下创建了一个名为 gfx 的文件夹,并将我的 splash.png 放在那里。
当我调用启动画面时:
public void loadSplashScreen()
{
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
splashTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 390, 534, TextureOptions.BILINEAR);
splash_region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(splashTextureAtlas, activity, "splash.png", 0, 0);
splashTextureAtlas.load();
}
这是产生的错误
我是不是放错地方了?资产应该放在哪里?
E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:52)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:43)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:86)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:82)
at com.waylonhuang.game.ResourcesManager.loadSplashScreen(ResourcesManager.java:68)
at com.waylonhuang.game.SceneManager.createSplashScene(SceneManager.java:93)
at com.waylonhuang.game.GameActivity.onCreateScene(GameActivity.java:62)
at org.andengine.ui.activity.BaseGameActivity.onCreateResourcesFinished(BaseGameActivity.java:171)
at com.waylonhuang.game.GameActivity.onCreateResources(GameActivity.java:45)
at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:183)
at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:112)
at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:21.329 30718-30749/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:101)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:85)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:154)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:21.348 30718-30749/com.waylonhuang.game W/dalvikvm﹕ threadid=15: thread exiting with uncaught exception (group=0x41717d40)
01-17 16:48:21.349 30718-30749/com.waylonhuang.game E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 6799
Process: com.waylonhuang.game, PID: 30718
org.andengine.util.exception.NullBitmapException: Caused by: class org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource --> AssetBitmapTextureAtlasSource(gfx/splash.png) returned a null Bitmap.
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:156)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:48:23.282 30718-30749/com.waylonhuang.game I/Process﹕ Sending signal. PID: 30718 SIG: 9
01-17 16:59:01.645 2098-2098/com.waylonhuang.game D/dalvikvm﹕ Late-enabling CheckJNI
01-17 16:59:02.020 2098-2098/com.waylonhuang.game I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8226_LNX.LA.3.5.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/07/14 Fri
Local Branch:
Remote Branch: quic/LNX.LA.3.5.1_RB1.1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING
01-17 16:59:02.052 2098-2098/com.waylonhuang.game D/OpenGLRenderer﹕ Enabling debug mode 0
01-17 16:59:02.087 2098-2119/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:52)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:43)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:86)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:82)
at com.waylonhuang.game.ResourcesManager.loadSplashScreen(ResourcesManager.java:68)
at com.waylonhuang.game.SceneManager.createSplashScene(SceneManager.java:93)
at com.waylonhuang.game.GameActivity.onCreateScene(GameActivity.java:62)
at org.andengine.ui.activity.BaseGameActivity.onCreateResourcesFinished(BaseGameActivity.java:171)
at com.waylonhuang.game.GameActivity.onCreateResources(GameActivity.java:45)
at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:183)
at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:112)
at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:59:02.106 2098-2119/com.waylonhuang.game E/AndEngine﹕ Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: gfx/splash.png
java.io.FileNotFoundException: gfx/splash.png
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:101)
at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:85)
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:154)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
01-17 16:59:02.110 2098-2119/com.waylonhuang.game W/dalvikvm﹕ threadid=15: thread exiting with uncaught exception (group=0x41717d40)
01-17 16:59:02.111 2098-2119/com.waylonhuang.game E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 7084
Process: com.waylonhuang.game, PID: 2098
org.andengine.util.exception.NullBitmapException: Caused by: class org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource --> AssetBitmapTextureAtlasSource(gfx/splash.png) returned a null Bitmap.
at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:156)
at org.andengine.opengl.texture.Texture.loadToHardware(Texture.java:145)
at org.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:268)
at org.andengine.engine.Engine.onDrawFrame(Engine.java:633)
at org.andengine.opengl.view.EngineRenderer.onDrawFrame(EngineRenderer.java:105)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
您必须在路径 app/src/main/ 中创建 "assets" 文件夹,并将带有 splash.png 的 "gfx" 文件夹放入其中
如果您使用的是 Eclipse,您应该直接从 Eclipse 创建 "gfx" 文件夹,然后将 splash.png 图片拖放到该文件夹中,确保您复制出现提示时,文件,而不是 link 它。 链接会产生可访问性问题。 这是我在 eclipse 中的一个小项目的工作项目结构:
这是我的调用方法的样子:
public void loadSplashResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/splash/");
mSplashTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(), 480, 800, TextureOptions.BILINEAR);
mSplashTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mSplashTextureAtlas, mActivity, "splash.png", 0, 0);
mSplashTextureAtlas.load();
mFont1 = FontFactory.create(mActivity.getFontManager(), mActivity.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), 10, Color.GRAY);
mFont1.load();
}
还有一个用于资源优化目的的卸载方法是明智的:
public void unloadSplashResources() {
mSplashTextureAtlas.unload();
mSplashTextureRegion = null;
mFont1.unload();
mFont1 = null;
}
在我的主activity中,然后我在加载资源时调用启动画面的加载:
@Override
protected void onCreateResources() {
mResourceManager = ResourceManager.getInstance();
mResourceManager.prepare(this);
mResourceManager.loadSplashResources();
mSceneManager = SceneManager.getInstance();
}
创建新场景后,我卸载启动画面:
@Override
protected Scene onCreateScene() {
mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
mEngine.unregisterUpdateHandler(pTimerHandler);
mResourceManager.loadGameResources();
mSceneManager.setScene(SceneType.SCENE_MENU);
mResourceManager.unloadSplashResources();
}
}));
希望您可以交叉参考这些样本,看看您的启动画面是否有类似配置的地方,并找到问题的原因。