————–> +1 Google if you want to help other devs to fix that issue <————–

You might have seen that gradiants on boxes and on backgrounds are quite ulgly…

Indeed Android rendering in 16 bit is quite tricky… because I need 24 bits for my png !

And so I needed to go for true RGBA_8888 !

In short, I found how to fix it.

Well watch the result and compare to your device :

For those who search how to do that on AndEngine, I found the solution on the AndEngine forum creating this class as root of my game Activities :

public abstract class MyGameActivity extends LayoutGameActivity{

@Override
protected void onSetContentView() {

super.setContentView(this.getLayoutID());

this.mRenderSurfaceView = (RenderSurfaceView) this.findViewById(this.getRenderSurfaceViewID());

this.mRenderSurfaceView.setEGLConfigChooser(false);
mRenderSurfaceView.setEGLConfigChooser(8,8,8,8,0,0);//!!
this.mRenderSurfaceView.setRenderer(this.mEngine);
mRenderSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);//!
};

}

For standard Android application, I use :

public abstract class RgbaActivity extends Activity{

//permet d’activer le support d’activity aux fenêtres 32 bits pour éviter les pbs de Bandering
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
}

you can also use dithering on drawable using XML :

android:dither= »true »;

but the results aren’t as good as the method above.

Finally you can activate dither using java by getting the drawable through Drawable d = getResources().getDrawable(R.drawable.ss_background);

and use d.setDither(true);

For backgrounds gradient, use something like this :

View l = findViewById(R.id.rLayout1);
l.getBackground().setDither(true);

Hope this will be useful for some people 🙂

Publicités