flash - AS3 掩码奇怪的结果

标签 flash actionscript-3 actionscript mask

我正在为我正在制作的益智游戏的一部分使用动态 mask 。

我有一个 6 block 的测试拼图。拼图分为 3 层:

  • 黑色形状 = 这是你放棋子的地方
  • 成品件 = 这是一个显示已找到件件的组合结果的图层
  • 散件 = 可以移动到位。

  • 黑色形状没问题,这只是对结果 Sprite 的简单颜色变换。

    当我将完成的部分组合成一个 Sprite 时,我注意到这些部分之间的间隙小于发际线。这看起来不太好,所以我一直在想办法解决这个问题:

    我想到的一种方法是在完整的结果 Sprite 上放置一个 mask ,以便只有找到的部分可见。我会在碎片周围添加一个 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,

    亲切的问候,
    杰伦

    最佳答案

    我知道您要做什么,但我不确定为什么它不适合您。我创建了一个类似的程序,它按预期工作:

    //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

    我能想到的唯一一件事是,您添加到蒙版 Sprite 中的部分相互覆盖,类似于在单个图形调用中重叠两个或多个形状时发生的情况:
    //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

    关于flash - AS3 掩码奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6852941/

    相关文章:

    javascript - 如何保持 HTML 页面中 SWF 文件的大小?

    flash - 在Actionscript中绘制三次贝塞尔曲线?

    flash as3 删除所有子项

    actionscript-3 - AS3计算特定坐标内的TUIO点

    actionscript-3 - 语法错误: expecting identifier before this. expecting colon before leftparen. expecting identifier before rightbrace

    actionscript-3 - Flash AS3安全沙箱违规/s.ytimg.com

    xml - 始终在 FB 4.6 中获得 XML 响应

    apache-flex - 在 Flex 中将字符串拆分为数组

    javascript - 为什么 ExternalInterface 在 Flash ide 中可用

    javascript - ActionScript/JavaScript 中的短路运算符在哪里?