How can I make the white rectangle continually and smoothly follow the cursor position using the move function with a tween?
What I've got so far doesn't work properly — the rectangle position only updates sporadically!
https://jsfiddle.net/jamesgreig/gaxrteoc/73/
var width = 1200
var height = 800
var draw = SVG('drawing').size(width, height)
var building = draw.rect(1200, 800).fill('https://www.dropbox.com/s/pidx5gd1cmt3kyx/mcw_elevation_small.jpg?raw=1')
var rect1 = draw.rect(300,80).fill('#FFF')
rect1.center(width/2, height/2)
var mask2 = draw.mask().add(rect1)
building.maskWith(mask2)
///////
var xPos = 300;
var yPos = 600;
onmousemove = function(e){
xPos = e.clientX
yPos = e.clientY
console.log(xPos+' , '+yPos)
}
/////
function update(dt) {
// move the rectangle towards the cursor
rect1.animate(300).move(xPos - 300, yPos - 80)
}
///////
var lastTime, animFrame;
function callback(ms) {
// we get passed a timestamp in milliseconds
// we use it to determine how much time has passed since the last call
if (lastTime) {
update((ms-lastTime)/1000) // call update and pass delta time in seconds
}
lastTime = ms
animFrame = requestAnimationFrame(callback)
}
callback()