0

I am trying to animate, from not follow a Component, to follow a Component - and then lastly animate back again to not following the component.

// this.camera.follow = Tween()
this.camera.followBodyComponent(SomeComponent);

Do you know how?

I tried something like this:

  bool tappedComponent = false;
  Vector2 cameraGoToPosition = Vector2(0,0);
  Vector2 cameraFromPosition = Vector2(0,0);

  void zoomTo(BodyComponent body, Vector2 vec){
    cameraFromPosition = body.center;
    camera.follow = cameraGoToPosition;
  }

  @override
  void update(double dt) {
    super.update(dt);
    cameraGoToPosition = cameraGoToPosition * dt;
    camera.position = cameraGoToPosition;
  }

But camera.position has no setter or getter?

Update: found that:

camera.moveTo(body.center);
// camera.moveTo(worldToScreen(body.center));

Is moving in an animated way, but it do not put the Component in the center of the screen?

Chris G.
  • 23,930
  • 48
  • 177
  • 302

1 Answers1

1

The easiest way currently is probably to just do:

camera.moveTo(body.center + camera.canvasSize / 2);

This will be improved for the CameraComponent API.

spydon
  • 9,372
  • 6
  • 33
  • 63