0

I'm using Andengine to create and android app, and I'm wondering if there is any possible way to change the background colour in a gradient fashion.

I know you can create a gradient in Andengine and thats from one part of the screen to another I what each colour in the gradient to fill the screen as it changes over time.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jtino
  • 27
  • 1
  • 1
  • 9

1 Answers1

0

If you are using the anchor center branch of andengine then you can just import the Gradient Class from org.andengine.entity.primitive.Gradient and set it's height and width to the camera width and height as shown:

final int CameraHeight = 480;
final int CameraWidth = 480;
int directionX = 1;
int directionY = 1;
Gradient g = new Gradient(0,0,CameraWidth,CameraHeight,
this.getVertexBufferObjectManager());
g.setGradient(yourFirstColor,yourSecondColor,directionX,directionY);

And then all you must do is attach it to your scene as the first child scene.attachChild(g);

Then to make it change over time you can register an update handler with the scene that changes the colors or changes the direction like:

scene.registerUpdateHandler(new IUpdateHandler(){
@Override
onUpdate(float pSeconds){
//Change the color or the direction of the gradient
}
});

or you could register an entity modifier like ColorModifier

ColorModifier cm = new ColorModifier(5, Color.BLUE, Color.GREEN);
g.registerEntityModifier(cm);