我做一个小划痕/基础上,AlphaMaskFilter例子揭示游戏: http://createjs.com/demos/easeljs/AlphaMaskReveal.html如何检测到AlphaMaskFilter在easeljs/createjs完全消失
我想检测到面膜完全消失,或使用阈值(例如90%划伤)。
我阅读AlphaMaskFilter,形状和图形对象上的文档,我不知道如何实现这一点。
林甚至不知道我已经获取像素信息并检查alpha通道来检测它,但即使如此,我不知道我是否会出现性能问题。
欢迎任何帮助,谢谢。
**** ****编辑添加到接受的答案****
所以,我能够拥有的使用AlphaMapFilter(感谢兰尼)透明度PCT。 AlphaMapFilter为您提供映射到所有像素的Alpha通道。 这里是为我工作的一个小示例代码:
// mShapeToScratch is a createjs Shape. like in the http://createjs.com/demos/easeljs/AlphaMaskReveal.html example
var alphaMaskFilter = new createjs.AlphaMapFilter(mShapeToScratch.cacheCanvas);
var canvas = alphaMaskFilter.alphaMap;
var ctx = canvas.getContext("2d");
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var alphaData = imgData.data;
var pixelTotal = rect.h*rect.w;
var transparentPixel = 0;
// rect.h is the height of the image and rect.w is the width not shown in the example
for (var y = 0; y < rect.h; ++y)
{
for (var x=0; x < rect.w; ++x)
{
var pixelIdx = (y*rect.w + x);
if(alphaData[pixelIdx] > 128) // transparent will be 255.
{
transparentPixel++;
}
}
console.log("transparent % = " + transparentPixel/pixelTotal);
此示例检查所有的像素,但它很容易地检查每一个x像素,以速度高达支票兰尼建议。
谢谢Lanny,如果我理解正确,你的意思是说 A)没有简单的方法来检测AlphaMaskFilter的显示量。 和 B)如果我想使用像素检查解决方案,我不能使用AlphaMaskFilter,我应该使用AlphaMapFilter。 我了解correclty吗? – ManriK
的排序。 AlphaMapFilter使用特定频道,因此您可以提供压缩的JPG作为蒙版。你将不得不做一个使用AlphaMapFilter方法的自定义过滤器(检查像素),改变它来检查alpha,然后实现某种覆盖算法。 – Lanny