无法在angengine中显示SVG

时间:2012-10-20 11:30:34

标签: java android andengine

我正在尝试使用andengine将SVG渲染到屏幕,但遗憾的是它没有显示。此外,我在运行项目时没有遇到任何异常或错误,因此我发现它很难调试。

我看过this post,但我想GLES2上没有BlackPawnTextureBuilder

我在下面列出了部分代码,

public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception
{
BuildableBitmapTextureAtlas buildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
logoSplashITextureRegion = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(buildableBitmapTextureAtlas, this, "gfx/BrickRed.svg", 80, 40);
buildableBitmapTextureAtlas.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}

public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception
{
logoSplashScene = new Scene();
logoSplashSprite = new Sprite(0, 0, logoSplashITextureRegion,mEngine.getVertexBufferObjectManager())
{
@Override
protected void preDraw(GLState pGLState, Camera pCamera)
{
    super.preDraw(pGLState, pCamera);
    pGLState.enableDither();
}
};
logoSplashSprite.setPosition((CAMERA_WIDTH - logoSplashSprite.getWidth()) * 0.5f, (CAMERA_HEIGHT - logoSplashSprite.getHeight()) * 0.5f);
logoSplashScene.attachChild(logoSplashSprite);
pOnCreateSceneCallback.onCreateSceneFinished(BrickActivity.logoSplashScene);
}

我忘记了代码中的某些内容吗? 在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我终于成功了。

似乎我正在使用GLES2,我必须在加载textureAtlas之前包含以下行。

buildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));

现在我的onCreateResources看起来像这样,

try
{
buildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(textureManager, 2048, 2048, TextureOptions.BILINEAR);
SVG redBrick = SVGParser.parseSVGFromAsset(assertManager, "gfx/BrickRed.svg");
iTextureRegion = SVGBitmapTextureAtlasTextureRegionFactory.createFromSVG(buildableBitmapTextureAtlas, redBrick, 80, 40);
buildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
buildableBitmapTextureAtlas.load();
} catch (TextureAtlasBuilderException e)
{
e.printStackTrace();
}