如果你不在 Box2d 中,你必须使用Pixel-Perfect Collision library。好默认的AndEngine库,不支持像素完美碰撞。要获得此支持,您需要在 eclipse 中导入此库并将其添加到您的项目使用库中。
在这里,我演示如何使用这个库。当你为你的精灵定义 Texture 和 Atlas 时,如下所示。
private BitmapTextureAtlas lifeAtlas;
public PixelPerfectTiledTextureRegion life_Texture;
PixelPerfectTextureRegionFactory.setAssetBasePath("gfx/game/");
lifeAtlas = new BitmapTextureAtlas(textureManager, 1280, 128,
TextureOptions.BILINEAR);
life_Texture = PixelPerfectTextureRegionFactory.createTiledFromAsset(
lifeAtlas, activity, "heart_tiled.png", 0, 0, 10, 1, 0);
lifeAtlas.load();
对于您的自定义精灵类,
public class Plane extends PixelPerfectAnimatedSprite {
public Plane(float pX, float pY,
PixelPerfectTiledTextureRegion pTiledTextureRegion,
VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTiledTextureRegion, pVertexBufferObjectManager);
setColor(Color.GREEN);
}
}
您还需要对 AndEngine 库进行一些调整才能使用它。关注this 话题即可。