Retrieving percentage of colors of a MovieClip

时光总嘲笑我的痴心妄想 提交于 2020-01-03 04:48:07

问题


today my question is as follows:

I have a game, and one of the phases is that you have to pass a "protective cream" on the doll's body. I already have this effect (image below), I'm using an alpha filter combined with a mask that is drawn.

I wonder how can I do to be checking after 20 seconds of the game, if the user has filled 100% of the masks ...

My code is this (forgive me, I am beginner and Brazilian ... any questions ask me):

stop();
import flash.display.Shape;
import flash.events.Event;
import flash.display.BlendMode;
import flash.display.BitmapData;
import flash.utils.Timer;

var tempoFase2:Timer = new Timer(10000, 1);

var corpo_creme:MovieClip = new corpo_mask();
addChild(corpo_creme);
corpo_creme.x = corpo_branco.x;
corpo_creme.y = corpo_branco.y;

setChildIndex(corpo_branco, 1);
setChildIndex(cabeca, 3);
setChildIndex(corpo_creme, 2);

var drawing:Shape = new Shape();
addChild(drawing);

corpo_creme.mask = drawing;
corpo_branco.blendMode = BlendMode.LAYER;

stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);

function draw(e:Event):void {
    drawing.graphics.beginFill(0xFFFFFF);
    drawing.graphics.drawCircle(mouseX,mouseY,30);
    drawing.graphics.endFill();
}

Thank U.


回答1:


Try this solution:

https://stackoverflow.com/a/15354416/1627055

Basically, you run BitmapData.threshold() against a mask of type BitmapData. You can also draw the relevant portion of your drawing over a temporary BitmapData object and do the same trick, make sure though that your algorithm will count the areas that are not covered by your drawing as filled - you can achieve this by creating the bitmap data pre-filled with white.



来源:https://stackoverflow.com/questions/28164098/retrieving-percentage-of-colors-of-a-movieclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!