Paper.js: Draging view with mouse

Created on 6 Jun 2016  路  2Comments  路  Source: paperjs/paper.js

Hello, I just want to drag the 'global' view with the mouse.

I tryed this:

function onMouseDrag(event) {
  view.center -= event.delta;
}

But the results isn't really great : https://youtu.be/5fygEzR61eA
Globally it's work but there is some 'bumps'.

note : i prefer do not use jQuery

Thank you

Most helpful comment

The example above pans the view relative on each step (drag event). It's a very annoying behavior. Try this to absolutely drag the view like expected. It's 1:1 pixel perfect position.

function onMouseDrag(event) {
  // The first lastMousePoint comes from onMouseDown.
  lastViewCenter = view.center;
  view.center = view.center.add(
    lastMousePoint.subtract(event.point)
  );
  lastMousePoint = event.point.add(view.center.subtract(lastViewCenter));
}

demo

All 2 comments

Below code might be less fluctuation. Please try it.

var c = new Point();
function onMouseDown(event){
  c = view.center.subtract(event.point)
}
function onMouseDrag(event){
  view.center = c.add(event.point);
}

Btw, support questions should be posted to the mailing list: http://groups.google.com/group/paperjs
This is a bug database, thus, please help to keep free from support questions. Thanks.

The example above pans the view relative on each step (drag event). It's a very annoying behavior. Try this to absolutely drag the view like expected. It's 1:1 pixel perfect position.

function onMouseDrag(event) {
  // The first lastMousePoint comes from onMouseDown.
  lastViewCenter = view.center;
  view.center = view.center.add(
    lastMousePoint.subtract(event.point)
  );
  lastMousePoint = event.point.add(view.center.subtract(lastViewCenter));
}

demo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

croqaz picture croqaz  路  6Comments

BHuys picture BHuys  路  3Comments

khurramraheel picture khurramraheel  路  7Comments

wes-r picture wes-r  路  3Comments

sansumbrella picture sansumbrella  路  3Comments