【问题标题】:Change background colour as gradient将背景颜色更改为渐变
【发布时间】:2014-06-28 23:36:12
【问题描述】:

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

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

【问题讨论】:

    标签: android background andengine gradient


    【解决方案1】:

    如果您使用的是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);
    

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多