하나 - 당신은 투명성을 가지고 있으며, 장소에 불투명 차폐의 BitmapData을하는 당신을 플레이어에게 칠할 필요가 있습니다. 필요에 따라 색상을 지정하지만 색상이 완전히 불투명한지 확인하십시오. 그런 다음 histogram()
을 수집 한 다음 255 번째 값에 대해 알파 벡터를 쿼리하면 0 % 채우기의 초기 값이됩니다. 범위는 0-255이므로 100이나 다른 고정 값을 사용할 수 없습니다. 그런 다음 플레이어가 페인팅하는 동안 BlendMode.ERASE
에 blendMode
매개 변수를 설정하여 해당 BitmapData 위에 브러시를 그립니다. 그러면 브러시가 그려지는 투명도를 얻기 위해 BitmapData가 정리됩니다. 플레이어가 그림 그리기를 마친 후 (예 : 페인트가 다 써 버린 경우) BitmapData에 histogram()
을 다시 실행하고 알파 채널 벡터의 255 번째 값을 쿼리합니다. 0은 비트 맵이 완전히 투명 함을 의미합니다 (또는 최소한 소량의 픽셀 만 불투명하게 유지됨). 따라서 0을 100 % 채우기로 사용할 수 있습니다.
var bd:BitmapData=new BitmapData(w,h,true,0x0); // fully transparent initial bitmap
bd.draw(yourPaintBase); // a shape that designates area to be painted. Must be fully opaque
var bm:Bitmap=new Bitmap(bd);
// position it as needed, so the area which should be painted is aligned to wherever you need
addChild(bm);
addEventListener(Event.ENTER_FRAME,doPaint);
var baseValue:int=bd.histogram()[3][255]; // Vector #3 contains alpha, #255 contains
// percentage of those pixels that have alpha of 255 = fully opaque
function doPaint(e:Event):void {
if (!areWePainting) return;
var sh:Shape=getBrush(); // shuold return an existing Shape object reference for performance
sh.x=e.localX;
sh.y=e.localY; // we are drawing where the mouse is
bd.draw(sh,null,null,BlendMode.ERASE);
decreasePaint(); // we have used some paint
if (noMorePaint()) {
e.target.removeEventListener(Event.ENTER_FRAME,doPaint);
var endValue:int=Math.floor(100*(1-bd.histogram()[3][255]/baseValue));
// aligning to percentage. This is the value you seek
reportFilledPercentage(endValue);
}
}
답변이 다른 것보다 조금 더 어렵습니다. . 그러나 내가 그 일을하는 너의 방법을 습득하면, 내가 쉴드 뒤에서 원하는 이미지를 놓을 수있다. 나는 당신의 대답을 먼저 시도 할 것이고, 그것이 나에게 너무 복잡해지면 나는 다른 것을 시도 할 것이다. 답변을 투표 할 수 없습니다. 나는 어떤 사람들을 돕기 위해 노력할 것이고, 15 가지 평판을 얻었을 때 나는 definatelly 당신을 업 그레 이드 할 것이다. – Pyva