Fabric.js - 动画时每 400 毫秒获取 oCoords 对象

Fabric.js - get oCoords object every 400ms while animating

在 Fabric.js 中,是否可以在动画中获取形状的坐标?我正在使用此处定义的对象来获取形状坐标:

http://fabricjs.com/docs/fabric.Object.html#oCoords

这是一个例子:

http://fabricjs.com/static_canvas/

当我在我的代码中获取这些对象点时,它只获取动画开始和结束时的点,我试图每 400 毫秒收集一次动画形状的 oCoords 数据:

window.setInterval(function(){
   attrSniperBrX = Math.round(snipers[index].oCoords.br.x); 
   attrSniperBrY = Math.round(snipers[index].oCoords.br.y); 
   heatMapAdd(attrSniperBrX, attrSniperBrY);

   console.log(attrSniperBrX, attrSniperBrY);
 }, 400);

您必须手动调用 setCoords() 方法。 由于主线程的性能原因,它不会在动画上自动调用。在 setInterval 上你应该没有问题。

window.setInterval(function(){
   /* guessing that sniper array contains fabricjs objects */
   snipers[index].setCoords();
   attrSniperBrX = Math.round(snipers[index].oCoords.br.x); 
   attrSniperBrY = Math.round(snipers[index].oCoords.br.y); 
   heatMapAdd(attrSniperBrX, attrSniperBrY);

   console.log(attrSniperBrX, attrSniperBrY);
 }, 400);