Пример #1
0
 private void createBackground() {
   this.autoParallaxBackground =
       new AutoParallaxBackground(0, 0, 0, 5) {
         @Override
         public void onUpdate(final float pSecondsElapsed) {
           super.onUpdate(pSecondsElapsed * BaseGameScene.this.parallaxFactor);
         }
       };
   this.setBackground(this.autoParallaxBackground);
   for (BackgroundElement layer : this.level.getBackgroundsElements()) {
     Sprite layerSprite =
         new Sprite(
             layer.x,
             GROUND_LEVEL + layer.y,
             this.resourcesManager.gameParallaxLayers.get(layer.getResourceName()),
             this.vbom);
     layerSprite.setColor(new Color(0.4f, 0.4f, 0.4f));
     this.backgroundParallaxLayers.add(layerSprite);
     layerSprite.setOffsetCenter(-1.5f, -1.5f);
     layerSprite.setScale(4f);
     this.autoParallaxBackground.attachParallaxEntity(
         new ParallaxBackground.ParallaxEntity(-layer.speed, layerSprite));
   }
 }
  @Override
  public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.getBackground().setColor(0.09804f, 0.6274f, 0.8784f);

    final int centerX = CAMERA_WIDTH / 2;
    final int centerY = CAMERA_HEIGHT / 2;

    final Sprite sprite =
        new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager());
    final PhysicsHandler physicsHandler = new PhysicsHandler(sprite);
    sprite.registerUpdateHandler(physicsHandler);

    scene.attachChild(sprite);

    /* Velocity control (left). */
    final AnalogOnScreenControl velocityOnScreenControl =
        new AnalogOnScreenControl(
            0,
            0,
            this.mCamera,
            this.mOnScreenControlBaseTextureRegion,
            this.mOnScreenControlKnobTextureRegion,
            0.1f,
            this.getVertexBufferObjectManager(),
            new IAnalogOnScreenControlListener() {
              @Override
              public void onControlChange(
                  final BaseOnScreenControl pBaseOnScreenControl,
                  final float pValueX,
                  final float pValueY) {
                physicsHandler.setVelocity(pValueX * 100, pValueY * 100);
              }

              @Override
              public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
                /* Nothing. */
              }
            });

    {
      final Sprite controlBase = velocityOnScreenControl.getControlBase();
      controlBase.setAlpha(0.5f);
      controlBase.setOffsetCenter(0, 0);

      scene.setChildScene(velocityOnScreenControl);
    }

    /* Rotation control (right). */
    final float y = (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) ? CAMERA_HEIGHT : 0;
    final AnalogOnScreenControl rotationOnScreenControl =
        new AnalogOnScreenControl(
            CAMERA_WIDTH,
            y,
            this.mCamera,
            this.mOnScreenControlBaseTextureRegion,
            this.mOnScreenControlKnobTextureRegion,
            0.1f,
            this.getVertexBufferObjectManager(),
            new IAnalogOnScreenControlListener() {
              @Override
              public void onControlChange(
                  final BaseOnScreenControl pBaseOnScreenControl,
                  final float pValueX,
                  final float pValueY) {
                if (pValueX == 0 && pValueY == 0) {
                  sprite.setRotation(0);
                } else {
                  sprite.setRotation(MathUtils.radToDeg((float) Math.atan2(pValueX, pValueY)));
                }
              }

              @Override
              public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
                /* Nothing. */
              }
            });

    {
      final Sprite controlBase = rotationOnScreenControl.getControlBase();
      if (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) {
        controlBase.setOffsetCenter(1, 1);
      } else {
        controlBase.setOffsetCenter(1, 0);
      }
      controlBase.setAlpha(0.5f);

      velocityOnScreenControl.setChildScene(rotationOnScreenControl);
    }

    return scene;
  }