我是新來的,如果我的問題很愚蠢,併爲我的英語感到抱歉,我很抱歉。 我的問題是,我有三層像下面的圖像。根據第三層的位置查看第二層 - Flash
「圖層1」的背景爲藍色,「圖層2」的顏色爲綠色。第3層具有透明背景的圖像。我想根據圖像邊距去除第二層。無論我移動圖像,我需要刪除第二層。想要的結果顯示在第二張圖片上。
我是新來的,如果我的問題很愚蠢,併爲我的英語感到抱歉,我很抱歉。 我的問題是,我有三層像下面的圖像。根據第三層的位置查看第二層 - Flash
「圖層1」的背景爲藍色,「圖層2」的顏色爲綠色。第3層具有透明背景的圖像。我想根據圖像邊距去除第二層。無論我移動圖像,我需要刪除第二層。想要的結果顯示在第二張圖片上。
你會希望把你的對象,這樣就可以對他們進行編程。由於空間做出糟糕的變量名,讓我們打電話給你的對象如下:
blue
person
解決方案
您需要一個遮罩,但與普通遮罩不同,您需要遮罩遮罩的反轉e(即,裏面是隱藏而不是裏面是顯示)。您可以通過BlendMode.ERASE實現此目的。然後,這只是匹配&尺寸person
的位置的問題;每當你移動person
時,也要更新掩碼的位置。
function make(color:uint, width:Number, height:Number, x:Number = 0, y:Number = 0, existingShape:Sprite = null):Sprite {
// Helper function to make squares. Will create a new one, or draw on one provided.
var s:Sprite;
if (existingShape != null) {
s = existingShape;
} else {
s = new Sprite();
}
s.graphics.beginFill(color, 1);
s.graphics.drawRect(x, y, width, height);
s.graphics.endFill();
return s;
}
// Layer 1
var blue:Sprite = make(0x3f48cc, 250, 400);
addChild(blue);
// Layer 2
var green:Sprite = make(0x00cc99, 250, 400);
addChild(green);
green.blendMode = BlendMode.LAYER;
// Layer 3
var person:Sprite = make(0xea0502, 20, 100, 20); // arms
make(0xea0502, 60, 20, 0, 20, person); // head and legs
addChild(person);
person.x = 95;
person.y = 150;
// This is the mask. It must be a child of the object it is masking.
var boundary:Sprite = make(0xff00e4, person.width, person.height);
green.addChild(boundary);
boundary.x = person.x;
boundary.y = person.y;
boundary.blendMode = BlendMode.ERASE;
結果
這就是我正在尋找的。謝謝 –
嗨,tonitox,歡迎計算器!如果你的英語不好,不要擔心,因爲有人通常會來和編輯你的帖子來澄清它。儘管如此,你將不得不描述你的意思。 「根據圖像邊距去除」是什麼意思? – ASCIIThenANSI
正如第二張圖片所示。我的意思是應該刪除第二層圖像的位置。我的意思是圖像的大小。換句話說,這個想法是在圖像下面顯示第一層。我希望你能理解我的意思。 –