Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS3掩码奇怪的结果_Flash_Actionscript 3_Actionscript_Mask - Fatal编程技术网

Flash AS3掩码奇怪的结果

Flash AS3掩码奇怪的结果,flash,actionscript-3,actionscript,mask,Flash,Actionscript 3,Actionscript,Mask,我正在玩动态掩蔽游戏,这是我正在制作的益智游戏的一部分 我有一个6块的测试拼图。谜题分为三层: 黑色形状=这是你放你的作品的地方 成品=这是一个显示已找到工件组合结果的图层 松散件=可移动到位 黑色形状没有问题,这只是结果精灵上的一个简单颜色变换 当我将成品组合成一个雪碧时,我注意到两个雪碧之间的间隙小于细线。这看起来不太好,所以我一直在想办法: 我想到的一种方法是在一个完整的结果精灵上放置一个面具,这样只有找到的碎片才可见。我会在碎片周围添加一个1px的边框,以避免出现发际线间隙 于是,我

我正在玩动态掩蔽游戏,这是我正在制作的益智游戏的一部分

我有一个6块的测试拼图。谜题分为三层:

  • 黑色形状=这是你放你的作品的地方
  • 成品=这是一个显示已找到工件组合结果的图层
  • 松散件=可移动到位
黑色形状没有问题,这只是结果精灵上的一个简单颜色变换

当我将成品组合成一个雪碧时,我注意到两个雪碧之间的间隙小于细线。这看起来不太好,所以我一直在想办法:

我想到的一种方法是在一个完整的结果精灵上放置一个面具,这样只有找到的碎片才可见。我会在碎片周围添加一个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;
//测试
var test:Sprite=newtestsprite()作为Sprite;
测试x=测试y=100;
addChild(测试);
//拼图
向量新向量。;
推(新的套头衫1());
推(新的套头衫2());
//推(新的套头衫3());
//推(新的套头衫4());
推(新的套头衫5());
推(新的套头衫6());
//每个工件的完工位置
变量点:向量=新向量。;
点推(新点(0.3,7.25));
推(新点(110.35,0));
//点.推(新点(98.25,52.6));
//点.推(新点(23.95,69.30));
点.推(新点(157.25,61.95));
点推(新点(146.7100.70));
变量掩码:Sprite=新Sprite();
for(变量i:int=0;i
完整形状和遮罩形状如下所示:

应用遮罩后,其外观如下所示:

我曾尝试将其缓存为位图,但没有结果。有人知道问题出在哪里吗

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;
}

我所能想到的唯一一件事是,添加到遮罩精灵中的各个部分相互重叠,类似于在单个图形调用中重叠两个或多个形状时发生的情况:

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

看起来像是cacheAsBitmapMatrix问题。你是这么说的吗?我不是这么说的。我已经尝试在没有运气的情况下为面具和测试精灵设置cacheABitmap=true。我还没有尝试cacheAsBitmapMatrix。好的,我现在尝试在掩码和测试精灵上设置cacheAsBitmapMatrix。同样的结果。选择整个蒙版并按ctrl+b十几次。应确保没有向量重叠(导入图形时就是这种情况)。可能是原因。这仅使用AS3动态完成。我做了你之前建议的测试,但结果是一样的。我又试了一些,但没能让它正常工作。我选择了另一条路,它做了我希望它做的事情:我不是把这些碎片粘在一起形成一个面具,而是把这些碎片粘在一起形成所示的图片。我以前试过,但接缝(非常小的开口)有问题。我纠正了这一点,将接缝处的碎片放大1倍(这样就有了有效的重叠,避免了孔洞)。