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;
完整形状和蒙版形状如下所示:
之后应用蒙版,它看起来像这样:
我尝试将其缓存为位图,但没有结果。任何人都知道问题可能是什么?
提前告知,
谨致问候, 杰罗恩
I'm playing around with dynamic masking for part of a puzzle game I'm making.
I've got a test puzzle with 6 pieces. The puzzle exists out of 3 layers:
- black shape = this is where you put your pieces
- finished pieces = this is a layer showing the combined result of found pieces
- loose pieces = can be moved into place.
The black shape is no problem, that's just a simple color transform on the result sprite.
When I combine the finished pieces in one sprite, I notice smaller than hairline gaps between the pieces. This doesn't look too good, so I've been thinking of a way around this:
One way I thought of was to put a mask on a complete result sprite so that only the found pieces are visible. I would add a 1px border around the pieces to avoid the hairline gaps.
So, I started playing around with masks:
// 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;
The full shape and the mask shape look like this:
After applying the mask it looks like this:
I have tried caching as bitmap, without result. Anyone have an idea what the problem could be?
Tnx in advance,
With kind regards,
Jeroen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白你正在尝试做什么,但我不确定为什么它不适合你。我创建了一个类似的程序,它按预期工作:
我唯一能想到的是您添加到蒙版精灵的片段会相互覆盖,类似于在单个图形调用中重叠两个或多个形状时发生的情况:
i see what you're attempting to do but i'm not sure why it's not working for you. i've created a similar program an it works as expected:
the only thing i can think of that the pieces you are adding to the mask sprite are overriting each other, similarly to what happens when you overlap two or more shapes within a single graphics call: