[英]Createjs masking with drawRect not working in Safari
I want to cut out some squares from a picture.我想从图片中剪下一些正方形。 The problem is that
Createjs
masking with drawRect
is not working in Safari.问题是使用
drawRect
屏蔽的Createjs
在 Safari 中不起作用。 Please check the following codepen in Safari请在 Safari 中检查以下代码笔
https://codepen.io/anon/pen/moXXRN
It works on all the browsers except Safari它适用于除 Safari 之外的所有浏览器
The issue with this is not masking or EaselJS, but how Safari handles winding rectangles drawn with negative coordinates.问题不在于遮罩或 EaselJS,而在于 Safari 如何处理使用负坐标绘制的缠绕矩形。 It looks like most browsers treat a rectangle with a one negative dimension as drawn in reverse, but Safari does not.
看起来大多数浏览器将一个负一维的矩形视为反向绘制,但 Safari 不会。
A super simple canvas example has the same problem:一个超级简单的画布例子也有同样的问题:
var ctx = document.getElementById("canvas").getContext("2d");
ctx.beginPath();
ctx.rect(50,50,50,50);
ctx.rect(150, 150, 50, 50);
ctx.rect(300, 0, 350, -350);
ctx.fillStyle = "red";
ctx.fill();
In most browsers, this draws the cut-out area.在大多数浏览器中,这会绘制剪切区域。 Safari does not.
Safari 没有。
Your solution of using your own lineTo()
commands is a good workaround.您使用自己的
lineTo()
命令的解决方案是一个很好的解决方法。
Managed to get it worked in Safari using lineTo
and moveTo
functions instead of drawRect
设法使用
lineTo
和moveTo
函数而不是drawRect
使其在 Safari 中工作
eg例如
shape.graphics.moveTo( 50, 50 );
shape.graphics.lineTo( 100, 50 );
shape.graphics.lineTo( 100, 100 );
shape.graphics.lineTo( 50, 100 );
shape.graphics.lineTo( 50, 50 );
shape.graphics.moveTo( 300, 0 );
shape.graphics.lineTo( 0, 0 );
shape.graphics.lineTo( 0, 300 );
shape.graphics.lineTo( 300, 300 );
shape.graphics.lineTo( 300, 0 );
https://codepen.io/anon/pen/EMEZMx https://codepen.io/anon/pen/EMEZMx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.