聽起來像是Alpha Mask的完美用例。
試試這個:
import spark.core.MaskType;
private function addMask():void {
var vidMask:SpriteVisualElement = new SpriteVisualElement();
// first mask the entire thing transparent
vidMask.graphics.beginFill(0x000000, 0);
vidMask.graphics.drawRect(0,0,480,320);
vidMask.graphics.endFill();
// then draw the rounded rectangle (or whatever) that you want to show
vidMask.graphics.beginFill(0x000000, 1); //color doesn't matter
vidMask.graphics.drawRoundRect(0,0,480, 320, 200, 200); // choose
vidMask.graphics.endFill();
addElement(vidMask); //the mask has to be on the Display List
vid.mask = vidMask; // attach the mask to the sve
vid.maskType = MaskType.ALPHA; // choose alpha masking
}
而在你的MXML:
<s:SpriteVisualElement id="vid" width="480" height="320" addedToStage="addMask()">
UPDATE
其實,現在我想過這個問題多一些,我的初步答案是誤導性的。你真的只需要有一個剪貼蒙版(不是一個Alpha),因爲不透明度沒有漸變。您可以按以下步驟更新addMask
功能:
private function addMask():void {
var vidMask:SpriteVisualElement = new SpriteVisualElement();
// draw the rounded rectangle (or whatever) that you want to show
vidMask.graphics.beginFill(0x000000, 1); //color doesn't matter
vidMask.graphics.drawRoundRect(0,0,480, 320, 200, 200); // the last two effect the roundness
vidMask.graphics.endFill();
addElement(vidMask); //the mask has to be on the Display List
vid.mask = vidMask; // attach the mask to the sve
vid.maskType = MaskType.CLIP; // choose clip masking
}
除非你最終會在你的面具使用分級不透明,這種方法將是可取的,因爲它應該簡化合成的玩家來進行。
有沒有原因你不使用s:Ellipse? –
我不介意它是否是橢圓形,圓角或任何與我的情況相匹配的東西。但我需要的是可視遠程視頻不會覆蓋其他東西! – Stefan