2011-07-28 4 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가 피처럼 보이는 흠집. 그걸 부르니? – 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