获取舞台区域内的所有影片剪辑

发布于 2024-09-27 07:25:51 字数 50 浏览 1 评论 0原文

有没有一种方法可以使用 AS3 获取某个区域内的所有影片剪辑,我需要它来进行多重选择。

Is ther a way to get all movie clips inside a area with AS3 I need this to do multiple selection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

゛时过境迁 2024-10-04 07:25:51

可能没有必要使用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);
    }
}

It might not be necessary to use getObjectsUnderPoint().
If all the items are in a single containing clip you could simply loop through the containers children and check if they are within your selection.

// 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);
    }
}
浊酒尽余欢 2024-10-04 07:25:51

我很确定没有任何“内置”东西可以将所有影片剪辑放入一个区域内。

唯一接近的可能是 getObjectsUnderPoint。此方法将为您提供单个点(而不是区域)下的 DisplayObject 列表,但可用于手动查找区域中的 MovieClip。

I am pretty sure there is nothing "built-in" that will get all the Movieclips inside an area.

The only thing that comes close is probably getObjectsUnderPoint. This method will give you the list of DisplayObjects under a single Point, not an area, but could be used to manually find MovieClips in a area.

蓝戈者 2024-10-04 07:25:51

你可以有一个精灵,它就是“区域”。这意味着它是您要检查的区域的大小。因此,只需循环遍历每个影片剪辑并使用 hitTestObject 或 hitTestPoint 检查影片剪辑是否与精灵碰撞。如果是这样,那么它就在那个区域。这就是我在 RTS 游戏中创建拖动和选择单位的方法。

You could have a sprite that is the "area". That meaning that it's the size of the area you want to check. So just loop through every movieclip and check with hitTestObject or hitTestPoint if the movieclip collides with the sprite. If so then it's in that area. This is how I create the drag and select units thing in RTS games.

魔法少女 2024-10-04 07:25:51

如果你想检查一个区域下的所有对象,你必须使用 for 循环和 hitTestPoint 方法。并且可以通过在此 for 循环上放置较大的增量来优化该循环。例如,如果您知道没有这样的宽度或高度小于 50 像素的对象,那么您将在嵌套循环中将 50 作为宽度或高度或两者的增量。
这是查找矩形区域或您指定的任何区域下的所有点的示例

(var j:int=Rect.x; j0)
{
跟踪(“找到的对象”+对象);
}
}
}

Well if you want to check all objects under an area , you have to use for loop with hitTestPoint method. and this loop can be optmized by putting large increment on this for loop. for example if you know that you have no such object whose width or height is smaller than 50 pixel then you will put 50 as the increment in the nested loop either on width or height or both..
here is the sample to find all points under the rectangle area or any area you specify

for(var j:int=Rect.x; j0)
{
trace ("found objects"+objects);
}
}
}

绝影如岚 2024-10-04 07:25:51

如果你想检查一个区域下的所有对象,你必须使用 for 循环和 hitTestPoint 方法。并且可以通过在此 for 循环上放置较大的增量来优化该循环。例如,如果您知道没有这样的宽度或高度小于 50 像素的对象,那么您将在嵌套循环中将 50 作为宽度或高度或两者的增量。
这是查找矩形区域或您指定的任何区域下的所有点的示例

(var j:int=Rect.x; j<=Rect.width; j++)
{

for(var i:int=矩形.y; i<=矩形.height; i++)
{

var pt:Point = 新点(x,y);

对象 = container.getObjectsUnderPoint(pt)

if(objects.length>0)
{
跟踪(“找到的对象”+对象);
}

}

}

Well if you want to check all objects under an area , you have to use for loop with hitTestPoint method. and this loop can be optmized by putting large increment on this for loop. for example if you know that you have no such object whose width or height is smaller than 50 pixel then you will put 50 as the increment in the nested loop either on width or height or both..
here is the sample to find all points under the rectangle area or any area you specify

for(var j:int=Rect.x; j<=Rect.width; j++)
{

for(var i:int=Rect.y; i<=Rect.height; i++)
{

var pt:Point = new Point(x,y);

objects = container.getObjectsUnderPoint(pt)

if(objects.length>0)
{
trace ("found objects"+objects);
}

}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文