5

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.

a_schimpf
  • 745
  • 1
  • 5
  • 16

1 Answers1

1

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));
MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98