2012-10-20 28 views
0

我想使用andengine將SVG呈現到屏幕,但不幸的是它沒有被顯示。另外,我在運行該項目時沒有遇到任何異常或錯誤,因此我發現調試非常困難。無法在angengine中顯示SVG

我看過this post,但我猜想BlackPawnTextureBuilder在GLES2上不可用。

我在下面列舉了我的代碼部分,

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); 
} 

我忘記了在代碼中的東西嗎? 在此先感謝您的幫助。

+0

哪個版本的Android,你運行這個嗎?只有3.0+版本才支持SVG。以前的版本不會渲染SVG,因此會變成空白。 – praneetloke

+0

我沒有安卓手機。因此我一直在使用android模擬器。 示例項目SVGTextureRegionExample運行時沒有問題。但我注意到示例項目擴展了'SimpleBaseGameActivity',而我擴展了'BaseGameActivity'。 –

回答

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(); 
}