canvas详解10-图形元素交互

介绍

isPointInPath()判断路径中是否包含监测点(作为参数传入)。

#isPointInPath()介绍

方法 描述 boolean ctx.isPointInPath(x, y) 判断监测点(x,y)是否在路径内 boolean ctx.isPointInPath(x, y, fillRule) 判断监测点(x,y)和路径的位置关系,通过fillRule来决定是路径内还是路径外。fillRule的可选参数是nonzero(非零环绕算法)和evenadd(奇偶环绕算法)

#使用

如果context.rect(10,10,100,100),那么所有在这个路径内的点都能被isPointInPath(x,y)判断为true,如(50,50);

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

ctx.rect(10, 10, 100, 100);
ctx.stroke();
con

猜你喜欢

转载自blog.csdn.net/qq_59747594/article/details/131350913