Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- moveTo(x, y) {
- const startX = this.coords.x,
- startY = this.coords.y,
- startTime = performance.now(),
- duration = Math.hypot(x-startX, y-startY)*3;
- let delta = 0;
- let self = this;
- const animate = function () {
- self.animating = true;
- const elapsed = performance.now() - startTime;
- delta = elapsed / duration;
- self.coords.x = startX + (x - startX) * delta;
- self.coords.y = startY + (y - startY) * delta;
- if(delta < 1 && !self.stop) return requestAnimationFrame(animate);
- self.animating = false;
- self.stop = false;
- };
- if(this.animating) this.stop = true;
- requestAnimationFrame(animate);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement