1

一段时间以来,我一直在用 AndEngine 驱动的动态壁纸解决一个严重的性能问题(在我完全不知道是什么原因之前,我已经发布了另一个关于它的问题),而且似乎唯一的方法是让它正常工作是将几个精灵合并在一起。

我有六个左右相当大的精灵,大小都一样,直接层叠在一起。我这样做是为了让它看起来像一个图像,但它的每个部分都可以通过代码设置为不同的颜色,只要我愿意。出于某种原因,在使用完全使用 alpha 的混合模式时分层精灵(即使图像中没有任何 alpha)会对您的帧速率造成重大损害,我找不到任何简单的解决方法这个。

我得到的解决方案是我需要单独对精灵做我需要做的事情,然后将它们合并为一个。我花了好几个小时潜入各种 AndEngine 类,试图在这个过程中不破坏任何东西,但我就是不知道该怎么做。

我敢肯定,将一个精灵拍打到另一个精灵上,或者以某种方式将重新加工的精灵放回临时纹理图集中并不是那么困难,我只是无法完全掌握如何让它继续下去。

编辑 ::

    public void onLoadResources(){
    this.mTestAtlas = new BitmapTextureAtlas(512, 1024, TextureOptions.NEAREST_PREMULTIPLYALPHA);

    Bitmap b = BitmapFactory.decodeStream(layer1);
    Bitmap a =  overlay(b);
    test = new BitmapTextureAtlasSource(a);

    this.mTesting = BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mTestAtlas, test, 0, 0);

    this.getEngine().getTextureManager().loadTexture(this.mTestAtlas);      
}   

public Scene onLoadScene(){
    layer1Sprite = new Sprite(x, y, width, height, this.mTesting);
    scene.attachChild(layer1Sprite);
}

public static Bitmap overlay(Bitmap bmp1) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);

    Paint layer1Paint = new Paint();
    ColorFilter layer1Filter;
    layer1Filter = new LightingColorFilter(Color.rgb(175, 0, 175), 1);
    layer1Paint.setColorFilter(layer1Filter);
    canvas.drawBitmap(bmp4, 0, 0, layer1Paint);

   return bmOverlay;

}
4

1 回答 1

1

Andengine does not provide any tools or methods to do this, but fortunately, native Android does. Here is an article that shows how to make a function that inputs two bitmaps but outputs one, merged bitmap.

http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas There is a related question here: Android merge two images

Update for Andengine GLES2:

AS of December 2011, there is a new version of Andrengine called Andengine GLES2. It has a built in resource for drawing your andengine sprites into a textures. Here is teh release note:

RenderToTexture/RenderTexture

Usage:

Render something into a Texture and use that texture for Sprites. (i.e. useful when rendering some complex mesh once and then efficiently drawing it again as a sprite.) Post-Processing effects

And the link to the original forum post outlining additions to GLES2.

http://www.andengine.org/forums/announces/andengine-gles2-pre-release-on-december-23rd-t6097.html

于 2011-12-19T19:37:49.447 回答