1

我正在尝试从已安装的 obb 扩展文件中加载纹理,但 AndEngine 无法打开此文件。那是我的代码:

    BuildableBitmapTextureAtlas atlas = new BuildableBitmapTextureAtlas(textureManager, 2048, 2048, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(obbManager.getMainRoot() + "/");
    File file = new File(obbManager.getMainRoot() + "/background.png");
    if (file.exists()) {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
    background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, this, "background.png");

这就是我在 Logcat 中看到的:

02-10 22:40:09.170: INFO/System.out(20962): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
02-10 22:40:09.180: ERROR/AndEngine(20962): Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: /mnt/obb/8d6d9efb8ab5fbfaa452d7ff7e8047c5/background.png
        java.io.FileNotFoundException: /mnt/obb/8d6d9efb8ab5fbfaa452d7ff7e8047c5/background.png
        at android.content.res.AssetManager.openAsset(Native Method)
        at android.content.res.AssetManager.open(AssetManager.java:315)
        at android.content.res.AssetManager.open(AssetManager.java:289)
        at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:48)
        at org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource.create(AssetBitmapTextureAtlasSource.java:39)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:140)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:132)
        at org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory.createFromAsset(BitmapTextureAtlasTextureRegionFactory.java:128)

因此,该文件存在,但我仍然收到 FileNotFoundException。

4

2 回答 2

1

我明白了:createFromAsset试图/mnt/.../background.png在 apk 中找到我的文件,而不是assets/mnt/.../background.png. 所以我应该使用 AndEngine 的 FileBitmapTextureAtlasSource:

BitmapTextureAtlasTextureRegionFactory.createFromSource(atlas, FileBitmapTextureAtlasSource.create(file))
于 2013-02-14T12:02:16.370 回答
0

请尝试使用这个

background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, getAssets(), "background.png");

代替

background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, this, "background.png");
于 2015-08-05T04:30:26.520 回答