我做一個小劃痕/基礎上,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