2014-06-28 302 views
0

我正在使用Andengine创建和Android应用程序,我想知道是否有任何可能的方式以渐变方式更改背景颜色。更改背景颜色作为渐变

我知道你可以在Andengine中创建渐变,并且从屏幕的一部分到另一个渐变中的每种颜色随着时间的推移而逐渐填充屏幕。

回答

0

如果您正在使用andengine的锚中心支公司,那么你可以从刚刚导入org.andengine.entity.primitive.Gradient梯度等级,并设置它的高度和宽度相机的宽度和高度,如下所示:

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); 

然后所有你必须做的是将其连接到场景的第一个孩子scene.attachChild(g);

然后让它随时间而改变,你可以注册,改变颜色或改变,如方向场景中的更新处理:

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

,或者你可以像ColorModifier

ColorModifier cm = new ColorModifier(5, Color.BLUE, Color.GREEN); 
g.registerEntityModifier(cm); 
注册实体修改