2014-01-26 44 views
0

嘗試使用andengine加載一個精靈實體,但精靈的底部和右側被切斷。Andengine GLES2精靈在底部和右側被修剪

enter image description here

代碼:

/* 
* Create the bitmap texture atlas for the sprite's texture region 
*/ 
BuildableBitmapTextureAtlas mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(
     mEngine.getTextureManager(), 256, 256, TextureOptions.BILINEAR); 

/* 
* Create the sprite's texture region via the 
* BitmapTextureAtlasTextureRegionFactory 
*/ 
mSpriteTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(
     mBitmapTextureAtlas, c, getSpriteId()); 

/* Build the bitmap texture atlas */ 
try 
{ 
    mBitmapTextureAtlas 
      .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
        0, 1, 1)); 
} 
catch (TextureAtlasBuilderException e) 
{ 
    e.printStackTrace(); 
} 

/* 
* Load the bitmap texture atlas into the device's gpu memory 
*/ 
mBitmapTextureAtlas.load(); 

mSprite = new Sprite(getInitialX(), getInitialY(), mSpriteTextureRegion, 
engine.getVertexBufferObjectManager()); 

/* Attach the marble to the Scene */ 

scene.attachChild(mSprite); 

回答

2

我建議你使用createFromAsset代替createFromResource只要有可能,因爲Android的重採樣資源,使得可變大小和壓縮質量的他們。 看來您的問題可能與此有關。

嘗試將image.png移動到assets文件夾,然後用它代替。

BitmapTextureAtlasTextureRegionFactory.createFromAsset(texture, context, "path_to/your_file.png"); 
+0

真棒,修復它。我想這意味着我必須手動管理DPI/sprite縮放比例吧? –

+1

很高興工作!並回答你關於管理DPI/sprite縮放的問題。答案是肯定的,有點。使用不同的ResolutionPolicy類型,您有一組工具。有很多寫在你的谷歌主題。你想要投入多少工作取決於你的項目。 –

-1
BuildableBitmapTextureAtlas mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(
     mEngine.getTextureManager(), 256, 256, TextureOptions.BILINEAR); 



/* Build the bitmap texture atlas */ 
try 
{ 
    mBitmapTextureAtlas 
      .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
        0, 1, 1)); 
} 
catch (TextureAtlasBuilderException e) 
{ 
    e.printStackTrace(); 
} 


/* 
* Create the sprite's texture region via the 
* BitmapTextureAtlasTextureRegionFactory 
*/ 
mSpriteTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(
     mBitmapTextureAtlas, c, getSpriteId(), 0, 0); 
/* 
* Load the bitmap texture atlas into the device's gpu memory 
*/ 
mBitmapTextureAtlas.load(); 


Try this 
+0

Rama:我覺得在使用BuildableBitmapTexture時添加紋理區域後他必須調用「build」。否則紋理區域將不會成爲構建紋理的一部分。 BuildableBitmapTexture的功能類似於使用spritesheet,但在運行時由andengine組裝。 –