将所有电影片段放在舞台区域内
-
29-09-2019 - |
题
是一种将所有电影剪辑带入AS3的区域中的一种方法,我需要做多次选择。
解决方案
可能没有必要使用 getObjectsUnderPoint().
如果所有项目都在包含夹子的单个中,则可以简单地循环浏览儿童的容器,然后检查他们是否在您的选择范围内。
// The list of items contained in the selection.
var selection:Array = new Array();
// The rectangle that defines the selection in the containers coordinate space.
var selectionRect:Rectangle = new Rectangle(x, y, width, height);
// Loop throught the containers children.
for(var a:int; a<container.numChildren; a++){
// Get the childs bounds in the containers coordinate space.
var child:DisplayObject = container.getChildAt(a);
var childBounds:Rectangle = child.getRect(container);
// Check if this childs bounds against the selection bounds
if(childBounds.intersects(selectionRect)){
selection.push(child);
}
}
其他提示
我很确定没有任何“内置”可以将所有移动装置都带到一个区域内。
唯一接近的事情可能是 getObjectsunderpoint. 。此方法将为您提供单个点下的DisplayObject列表,而不是一个区域,但可以用来手动在区域中找到MovieClips。
您可以拥有一个“区域”的精灵。这意味着这是您要检查的区域的大小。因此,只需循环遍历每个MovieClip,然后使用HittestObject或Hittestpoint检查MovieClip与Sprite碰撞。如果是这样,那就在那个区域。这就是我在RTS游戏中创建拖放和选择单元的方式。
好吧,如果您想检查区域下的所有对象,则必须使用HiteStpoint方法用于循环。并且可以通过将大量增量在此循环上进行大量增量来选择。例如,如果您知道自己没有这样的对象的宽度或高度小于50像素,那么您将将50个作为嵌套环的增量置于宽度或高度或两者。矩形区域或您指定的任何区域
for(var j:int = rect.x; j0){trace(“找到对象”+对象); }}}}
好吧,如果您想检查区域下的所有对象,则必须使用HiteStpoint方法用于循环。并且可以通过将大量增量在此循环上进行大量增量来选择。例如,如果您知道自己没有这样的对象的宽度或高度小于50像素,那么您将将50个作为嵌套环的增量置于宽度或高度或两者。矩形区域或您指定的任何区域
for(var j:int = rect.x; j <= rect.width; j ++){
for(var i:int = ect.y; i <= rect.height; i ++){
var pt:point =新点(x,y);
对象= container.getObjectsunderpoint(pt)
if(objects.length> 0){trace(“找到对象”+对象); }
}
}