Andengine GLES2精灵在底部和右侧剪裁

时间:2014-01-26 00:31:12

标签: android andengine

尝试使用andengine加载精灵实体,但精灵的底部和右侧被切断。

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 个答案:

答案 0 :(得分:2)

我建议您尽可能使用createFromAsset而不是createFromResource,因为Android重新采样资源,使其具有可变大小和压缩质量。 看来您遇到的问题可能与此有关。

尝试将image.png移动到assets文件夹,然后使用它。

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

答案 1 :(得分:-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