Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply gradient background in andengine

Tags:

java

andengine

I've been looking around for awhile now, and can't seem to find out how to set a scene's background as a gradient... it's hard to find solid Andengine-related answers,

I guess my options are:

  • using a sprite from a gradient image I've created myself (which can't be the best way)
  • using a gradient xml resource (but I don't know how to create a sprite from a resId, and I'm confused on how to make the gradient fit the camera)
  • or some other andengine built-in method

Any help is appreciated.

like image 800
a_schimpf Avatar asked Nov 13 '22 04:11

a_schimpf


1 Answers

The following code inside your activity class (onCreateScene or onPopulateScene) should set a red/blue gradient as your background.

Gradient g = new Gradient(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.getVertexBufferObjectManager());
g.setGradient(Color.RED, Color.BLUE, 1, 0);
this.setBackground(new EntityBackground(g));
like image 108
MartinTeeVarga Avatar answered Nov 14 '22 23:11

MartinTeeVarga