Paper.js Subraster Added Behind Rectangle Instead of in Front

与世无争的帅哥 提交于 2019-12-11 03:33:21

问题


In this Paper.js Sketch, selecting an area of the Mona Lisa raster makes a whiteout Rectangle of the area in place, as well as a generating a subraster of the area. The whiteout rectangle is added first, and the subraster second. However, as you witness in the sketch, the whiteout rectangle remains on top. Test this by commenting out the whiteout rectangle chunk and uncommenting the last line to see that the subraster does indeed get generated.

This can be remedied in this scenario with a call to bringToFront(), but that still doesn't explain why the subraster ends up behind the white rectangle, despite the fact that it was added last. What is the cause of this behavior? What is the logic going on here? Thanks in advance.


回答1:


If you look at the getSubRaster() function, you can see that it inserts the returned raster directly above the raster object it was created from.

function() {
  var rect = Rectangle.read(arguments),
    raster = new Raster(Item.NO_INSERT);
  raster.setImage(this.getSubCanvas(rect));
  raster.translate(rect.getCenter().subtract(this.getSize().divide(2)));
  raster._matrix.preConcatenate(this._matrix);
  raster.insertAbove(this);
  return raster;
}


来源:https://stackoverflow.com/questions/33676618/paper-js-subraster-added-behind-rectangle-instead-of-in-front

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!