How to tween view.center in paper.js

194 Views Asked by At

So I'm trying to give the feel of smooth movement when reassigning the paper.view.center coordinates. The center object doesn't have a tweenTo() method. This is what I've tried using Tween.js:

let smooth = new TWEEN.Tween(paper.view.center).to({
    x: 650,
    y: 270
}, 900).easing(TWEEN.Easing.Cubic.Out).start();

Since it's a Point object reassigning the x and y values don't actually change the coordinates, because the proper way of reassiging it is to use another Point object (new paper.Point()). How could I tween the continuously new creation of a Point object?

1

There are 1 best solutions below

1
sasensi On BEST ANSWER

I think that a simple way of achieving what you want is animating the active layer position.
Here's a sketch demonstrating a possible implementation.

const circle = new Path.Circle({
    center: view.center,
    radius: 50,
    fillColor: 'orange'
});
circle.clone().translate(100)

project.activeLayer.tweenTo(
    { position: { x: 50, y: 50 } },
    { duration: 700, easing: 'easeInOutQuad' }
);