获取舞台区域内的所有影片剪辑
有没有一种方法可以使用 AS3 获取某个区域内的所有影片剪辑,我需要它来进行多重选择。
Is ther a way to get all movie clips inside a area with AS3 I need this to do multiple selection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
可能没有必要使用
getObjectsUnderPoint()。
如果所有项目都在一个包含剪辑中,您可以简单地循环遍历容器子项并检查它们是否在您的选择范围内。
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.
我很确定没有任何“内置”东西可以将所有影片剪辑放入一个区域内。
唯一接近的可能是 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.
你可以有一个精灵,它就是“区域”。这意味着它是您要检查的区域的大小。因此,只需循环遍历每个影片剪辑并使用 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.
如果你想检查一个区域下的所有对象,你必须使用 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);
}
}
}
如果你想检查一个区域下的所有对象,你必须使用 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);
}
}
}