gpt4 book ai didi

flash - AS3 掩码奇怪的结果

转载 作者:行者123 更新时间:2023-12-01 07:47:40 27 4
gpt4 key购买 nike

我正在为我正在制作的益智游戏的一部分使用动态 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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com