SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. moveTo(x, y) {
  2.     const startX = this.coords.x,
  3.         startY = this.coords.y,
  4.         startTime = performance.now(),
  5.         duration = Math.hypot(x-startX, y-startY)*3;
  6.     let delta = 0;
  7.  
  8.     let self = this;
  9.     const animate = function () {
  10.         self.animating = true;
  11.         const elapsed = performance.now() - startTime;
  12.         delta = elapsed / duration;
  13.         self.coords.x = startX + (x - startX) * delta;
  14.         self.coords.y = startY + (y - startY) * delta;
  15.         if(delta < 1 && !self.stop) return requestAnimationFrame(animate);
  16.         self.animating = false;
  17.         self.stop = false;
  18.     };
  19.     if(this.animating) this.stop = true;
  20.     requestAnimationFrame(animate);
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top