2011-07-28 56 views
3

我玩弄動態遮罩的益智遊戲,我做的一部分。AS3面具怪異的結果

我有一個測試拼圖6件。存在了3層的難題:

  • 黑色形狀=這是你把你的片
  • 成品塊=此是表示發現片的組合的結果的層
  • 鬆散件=可以被移動到位。

黑色的形狀沒有問題,這只是一個簡單的結果精靈顏色轉換。

當我在一個精靈相結合完成的作品,我發現比片之間的髮際線的差距更小。這看起來並不太好,所以我一直在解決這個思維方式:我認爲

一種方法是把口罩上的完整結果精靈這樣只有找到的作品是可見的。我會在這些部分周圍添加一個1px邊框以避免髮際縫隙。

於是,我開始用口罩打轉轉:

// test 
var test: Sprite = new TestSprite() as Sprite; 
test.x = test.y = 100; 
addChild(test); 

// puzzle pieces    
var pieces: Vector.<Sprite> = new Vector.<Sprite>; 
pieces.push(new TurtlePiece1()); 
pieces.push(new TurtlePiece2()); 
//pieces.push(new TurtlePiece3()); 
//pieces.push(new TurtlePiece4()); 
pieces.push(new TurtlePiece5()); 
pieces.push(new TurtlePiece6()); 

// finished locations for each piece 
var points: Vector.<Point> = new Vector.<Point>; 
points.push(new Point(0.3, 7.25)); 
points.push(new Point(110.35, 0)); 
//points.push(new Point(98.25, 52.6)); 
//points.push(new Point(23.95, 69.30)); 
points.push(new Point(157.25, 61.95)); 
points.push(new Point(146.7, 100.70)); 

var mask: Sprite = new Sprite(); 
for (var i: int = 0; i < pieces.length; i++) { 
    pieces[i].x = points[i].x; 
    pieces[i].y = points[i].y; 
    mask.addChild(pieces[i]); 
} 
test.mask = mask; 

完整的形狀和遮罩形狀看起來像這樣:

full image and mask shape

將它看起來像這樣的面具後:

masked image

我試圖緩存爲位圖,沒有結果。任何人都有一個想法可能是什麼問題?

TNX提前,

隨着親切的問候,吉榮

+0

看起來像一個的cacheAsBitmapMatrix p roblem。你在打電話嗎? – TheDarkIn1978

+0

我不會這麼說。我試圖設置cacheABitmap = true爲掩碼和測試精靈沒有運氣。我沒有嘗試cacheAsBitmapMatrix。 – Jeroen

+0

好吧,我現在試圖設置的cacheAsBitmapMatrix的面具和測試精靈。同樣的結果。 – Jeroen

回答

1

我看到你正在試圖做什麼,但我不知道爲什麼它不爲你工作。我創建了一個類似的計劃的它按預期工作:

//Imports 
import flash.display.Shape; 
import flash.display.Sprite; 

//Draw Background Rect 
var backgroundRect:Shape = new Shape(); 
backgroundRect.graphics.beginFill(0x000000, 1.0); 
backgroundRect.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); 
backgroundRect.graphics.endFill(); 

addChild(backgroundRect); 

//Build Mask From Circles 
var backgroundMask:Sprite = new Sprite(); 

var circleA:Shape = circle(50, 0xFF0000); 
circleA.x = 50; 
circleA.y = 50; 

var circleB:Shape = circle(50, 0x00FF00); 
circleB.x = 100; 
circleB.y = 50; 

var circleC:Shape = circle(50, 0x0000FF); 
circleC.x = 150; 
circleC.y = 75; 

backgroundMask.addChild(circleA); 
backgroundMask.addChild(circleB); 
backgroundMask.addChild(circleC); 

addChild(backgroundMask); 

//Assign Mask 
backgroundRect.mask = backgroundMask; 

//Create Circle 
function circle(radius:uint, color:uint):Shape 
{ 
    var result:Shape = new Shape(); 
    result.graphics.beginFill(color, 1.0); 
    result.graphics.drawCircle(0, 0, radius); 
    result.graphics.endFill(); 

    return result; 
} 

enter image description here

我能想到的,你要添加到面具精靈的片overriting對方,類似的唯一的事情是什麼當您在一個圖形中重疊兩個或兩個以上的形狀發生致電:

//Imports 
import flash.display.Shape; 
import flash.display.Sprite; 

//Draw Circle 
var circleA:Shape = circle(50, 0xFF0000); 
circleA.x = 50; 
circleA.y = 50; 

addChild(circleA); 

//Create Circle 
function circle(radius:uint, color:uint):Shape 
{ 
    var result:Shape = new Shape(); 
    result.graphics.beginFill(color, 1.0); 
    result.graphics.drawCircle(0, 0, radius); 
    result.graphics.drawCircle(50, 50, radius); 
    result.graphics.endFill(); 

    return result; 
} 

enter image description here

+0

Tnx的答案。我已經嘗試了更多,無法正常工作。我選擇了一條不同的道路,而不是將它們粘合在一起形成一個蒙版,而是將這些部分粘合在一起形成顯示的圖片。我之前嘗試過,但接縫有問題(非常小的開口)。我通過在接縫處使塊大1px來糾正這種情況(所以存在有效的重疊,避免漏洞)。 – Jeroen