[英]Change background colour as gradient
我正在使用Andengine创建和运行android应用,我想知道是否有任何可能的方法可以以渐变方式更改背景颜色。
我知道您可以在Andengine中创建一个渐变,即从屏幕的一部分到另一部分,随着时间的推移,渐变中的每种颜色将填充整个屏幕。
如果使用的是andengine的锚点中心分支,则只需从org.andengine.entity.primitive.Gradient导入Gradient Class并将其高度和宽度设置为相机的宽度和高度,如下所示:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.