如何在AS3中制作面具

时间:2015-01-23 23:31:07

标签: actionscript-3 flash paint mask

我有一个duvifa:

我想知道是否可以按照下面的方式在movieClip中制作一个蒙版:

如果这张图片是游戏的开头。

enter image description here

当用户点击屏幕时,会创建一种奶油,但不会像他会在整个舞台上延伸,而只是以我的方式。

enter image description here

如下:

enter image description here

还想知道我是否可以获得表格填写的百分比,看看用户是否填写了至少40%。

谢谢你。

1 个答案:

答案 0 :(得分:1)

这是一个使用flashPro的简单示例,假设您将形状图形作为导入.png库对象,并为actionscript类导出MC

import flash.display.Shape;
import flash.events.Event;
import flash.display.BlendMode;

var mc:MC = new MC(); //the background image
addChild(mc);

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

var mcMask:MC = new MC(); //mask version of background image
addChild(mcMask);

var outerMask:Shape = new Shape(); //this object masks the areas outside the bounds of mcMask object
outerMask.graphics.beginFill(0);
outerMask.graphics.drawRect(0,0,mcMask.width,mcMask.height);
outerMask.graphics.endFill();
addChild(outerMask);

drawing.mask = outerMask; //the mask to the shape whose dimensions equal the image mask

mcMask.blendMode = BlendMode.ALPHA; //this tells the mask graphic to make things underneath it use the same alpha data as this image.  This works will with PNG masks.
this.blendMode = BlendMode.LAYER; //the parent needs to have a blend mode of LAYER for it to work properly

stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);

function draw(e:Event):void {
    trace("draw");
    drawing.graphics.beginFill(0x0000FF);
    drawing.graphics.drawCircle(mouseX,mouseY,10);
    drawing.graphics.endFill();
}