AndEngine动画精灵未显示

3

我刚开始使用动画精灵并添加了一个,但似乎无法工作,任何帮助将不胜感激。

它只显示为黑色方框。虽然背景出现了。我发现如果我没有使用(bi~).load();它会显示成黑色方框,但它有一个load();

日志记录

01-07 10:47:48.049: W/System.err(2879): org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder$TextureAtlasBuilderException: Could not build: 'AssetBitmapTextureAtlasSource(gfx/face_hexagon_tiled.png)' into: 'BitmapTextureAtlas'.
01-07 10:47:48.049: W/System.err(2879):     at org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder.build(BlackPawnTextureAtlasBuilder.java:87)
01-07 10:47:48.049: W/System.err(2879):     at org.andengine.opengl.texture.atlas.buildable.BuildableTextureAtlas.build(BuildableTextureAtlas.java:236)
01-07 10:47:48.059: W/System.err(2879):     at com.example.pilet.Game.onCreateResources(Game.java:48)
01-07 10:47:48.059: W/System.err(2879):     at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
01-07 10:47:48.059: W/System.err(2879):     at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
01-07 10:47:48.059: W/System.err(2879):     at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
01-07 10:47:48.059: W/System.err(2879):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
01-07 10:47:48.059: W/System.err(2879):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

我的课程

private Camera mCamera;
private int c_width = 640;
private int c_height = 480;
private BuildableBitmapTextureAtlas mBitmapTextureAtlas;
private TiledTextureRegion pi;
private Scene mScene;

@Override
public EngineOptions onCreateEngineOptions() {
    mCamera = new Camera(0, 0, c_width, c_height);
    EngineOptions options = new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
                    c_width, c_height), mCamera);
    return options;
}

@Override
public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback)
        throws Exception {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(
            this.getTextureManager(), 32, 32, TextureOptions.NEAREST);
    this.pi = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
            this.mBitmapTextureAtlas, this, "face_box_tiled.png", 2, 1);
    try {
        this.mBitmapTextureAtlas
                .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                        0, 0, 1));
        this.mBitmapTextureAtlas.load();
    } catch (Exception e) {
        Debug.e(e);
    }

    pOnCreateResourcesCallback.onCreateResourcesFinished();
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
        throws Exception {
    this.mScene = new Scene();
    this.mScene.setBackground(new Background(0.82f, 0.91f, 0.7121f));
    pOnCreateSceneCallback.onCreateSceneFinished(this.mScene);
}

@Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
    final AnimatedSprite piA = new AnimatedSprite(32, 32, pi,
            this.getVertexBufferObjectManager());
    piA.animate(100);
    this.mScene.attachChild(piA);

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

}

听起来像是尺寸问题 - 你的.png文件尺寸是多少?只是为了试试 - 将TextureAtlas的大小设置为128x128,看看是否有效。 - jmroyalty
1个回答

11

看起来你的精灵纹理在图集上没有足够的空间。尝试增加你的图集大小,使其大于或等于你的精灵大小 + 填充。


谢谢。我觉得仅从错误描述中我永远也不会弄对它... - kubilay

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