2011-09-12 103 views
0

我正在尋找一種讓我的spritevisualelement有圓角的方法,以便它以圓形顯示。BorderContainer as Foreground Object

SpriteVisualElement包含一個來自FMS的視頻流來顯示,但我不希望它是矩形。

有人給我提示?

<s:BorderContainer 
      borderColor="0x000000" 
      borderAlpha="50" 
      cornerRadius="150" 
      borderWeight="3" 
      x="161" 
      y="10" 
      > 
<s:SpriteVisualElement id="vid" width="480" height="320"/> 
      </s:BorderContainer> 
<s:SpriteVisualElement id="vid_self_preview" x="710" y="373" width="90" height="60"/> 

但是容器一直在後臺,顯示在「vid」(= id)中的整個遠程視頻位於前臺。 如何將容器設置爲前景?那麼只需設置整個應用程序背景就可以完成工作。

+0

有沒有原因你不使用s:Ellipse? –

+0

我不介意它是否是橢圓形,圓角或任何與我的情況相匹配的東西。但我需要的是可視遠程視頻不會覆蓋其他東西! – Stefan

回答

0

聽起來像是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 
    } 

除非你最終會在你的面具使用分級不透明,這種方法將是可取的,因爲它應該簡化合成的玩家來進行。

+0

這工作非常順利。在應用程序中使用黑色backgroundColor,這正是我想要做的!非常感謝你! 但是,請你解釋一下爲什麼使用哪種顏色填充圓角矩形並不重要? – Stefan

+0

明白了,爲什麼......認爲0xFF的alpha值意味着完全透明; – Stefan

相關問題