2014-01-26 3 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 в папку с ресурсами, а затем используйте его.

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. В противном случае области текстуры не будут частью встроенной текстуры. BuildableBitmapTexture функционирует подобно использованию спрайтов, но собирается во время выполнения командой andengine. –

Смежные вопросы