简体   繁体   English

使用 drawRect 进行的 Createjs 屏蔽在 Safari 中不起作用

[英]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设法使用lineTomoveTo函数而不是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM