Kinetic js mousemove设置了attrs

时间:2013-06-20 14:50:41

标签: kineticjs mousemove setattribute

当我鼠标移动到某个区域时,我想在鼠标移动时移动阴影。它适用于单击和补间,但不适用于mousemove。我想我必须更新舞台,因为如果在舞台上有不同的东西被修补它会工作一会儿,直到其他补间完成。 请提前帮助和谢谢。

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)],
  })                                                   
});

1 个答案:

答案 0 :(得分:0)

您可能需要致电layer.drawScene()stage.draw()来更新画布。在click和补间期间,它会自动调用。

您修改过的代码如下所示:

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 ;)                                        
});