gpt4 book ai didi

actionscript-3 - 如何确定给定对象是否为掩码

转载 作者:行者123 更新时间:2023-12-04 05:02:00 26 4
gpt4 key购买 nike

显然,在 Adob​​e 的智慧中,被蒙版的对象和蒙版对象都包含“蒙版”属性。这会导致循环引用,从而阻止确定哪个是实际掩码,哪个是被掩码。

例如...

var clip:MovieClip = new MovieClip();
clip.name = "clip";
addChild(clip);

var boundary:Shape = new Shape();
boundary.name = "boundary";
clip.addChild(boundary);

clip.mask = boundary;

trace(clip.mask.name); // outputs "boundary"
trace(clip.mask.mask.name); // outputs "clip"

我已经遍历了两个 clip 的属性和 boundary ,并且似乎没有任何独特之处使它们与众不同。我的第一个想法是强制删除 boundary 中多余的“掩码”引用。 ,但是,这也会设置 mask位于 clip 的属性(property)为空,从而删除掩码。

我的第二个想法是检查掩码的父关系。如果父对象与对象的掩码相同,则所讨论的对象本身就是掩码。
var a:Array = [clip, boundary];

for each (var item in a) {
if (item.mask == item.parent) {
trace(item.name + " is a mask");
}
}

// outputs "boundary is a mask"

似乎可以工作,在检查 API reference 之后在掩码上,很明显在缓存时,掩码将 需要但是,要成为蒙面的 child ……与蒙面的深度相同的蒙版也是有效的(当蒙版不需要与蒙面的内容一起移动时,我会不时这样做)。

例如...
MainTimeline ¬
0: clip ¬
0: boundary

...也可以布置为...
MainTimeline ¬
0: clip ¬
1: boundary

所以,有一个难题。关于如何解决这个问题的任何想法?

最佳答案

到目前为止,我发现的“最佳”hack 是运行 hitTestPoint在物体上(在确保它们在目标下方有东西可以击中之后)。口罩似乎永远不会返回 true进行全像素 HitTest 。这似乎适用于我测试过的大多数基本情况:

public function isMask(displayObject:DisplayObject):Boolean {

// Make sure the display object is a Class which has Graphics available,
// and is part of a mask / maskee pair.
if ((displayObject is Shape || displayObject is Sprite) && displayObject.mask) {

// Add a circle at the target object's origin.
displayObject['graphics'].beginFill(0);
displayObject['graphics'].drawCircle(0, 0, 10);

var origin:Point = displayObject.localToGlobal(new Point());
var maskLocal:Point = displayObject.mask.globalToLocal(origin);

// Add a circle at the same relative position on the "mask".
displayObject.mask['graphics'].beginFill(0);
displayObject.mask['graphics'].drawCircle(maskLocal.x, maskLocal.y, 10);

// No matter which is the actual mask, one circle will reveal the other,
// so hit testing the origin point should return true.
// However, it seems to return false if the object is actually a mask.
var hit:Boolean = displayObject.hitTestPoint(origin.x, origin.y, true);

displayObject['graphics'].clear();
displayObject.mask['graphics'].clear();

// Return true if the hit test failed.
return !hit;
} else {
return false;
}
}

显然你想缓存 graphics如果对象已经有一些,它可以做一些比转换为 Sprite 更优雅的东西,以便它可以处理 Shapes,但这是一个开始。

编辑:访问 ['graphics']让这个接受 Shape s,但显然不是 super 有效。我不确定最好的方法是什么,除了添加一个接口(interface)。

关于actionscript-3 - 如何确定给定对象是否为掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044632/

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