Question

I want to move a shadow on mousemove when I mousemove over an area. It works with a click and tween but not on mousemove. I guess I have to update the stage because if something different on stage is tweened it works for a short while till the other tween is finished. Please help and thanks in advance.

greyBack.on('mousemove', function() {
  var mousePos = stage.getMousePosition();
  var x = (mousePos.x) -  (stage.getWidth());
  var y = (mousePos.y) -  (stage.getHeight());

  shadow1.setAttrs({
    x: [x*(-1)],
    y: [y*(-1)],
  })                                                   
});
Was it helpful?

Solution

You might have to call layer.drawScene() or stage.draw() to update the canvas. On click and during tweens it gets called automatically.

Your modified code would look like that:

greyBack.on('mousemove', function() {
  var mousePos = stage.getMousePosition();
  var x = (mousePos.x) -  (stage.getWidth());
  var y = (mousePos.y) -  (stage.getHeight());

  shadow1.setAttrs({
    x: [x*(-1)],
    y: [y*(-1)],
  })     
  layer.drawScene(); //Or stage.draw(); - I don't know how you grouped your shapes ;)                                        
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top