Actionscript 3:在像素处获取显示对象 [英] Actionscript 3: get display object at pixel

查看:18
本文介绍了Actionscript 3:在像素处获取显示对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何枚举相对于舞台的像素下的显示对象?

How can I enumerate display objects under a pixel relative to the stage?

说明:我想编写一个函数,它以 (x,y) 作为输入并返回一个 对象数组 作为输出.

Clarification: I want to write a function which get (x,y) as input and returns an array of objects as output.

更新:我想避免遍历所有显示对象,以判断哪个在指定像素下.

update: I want to avoid looping over all the display objects, to tell which one is under the specified pixel.

推荐答案

任何 DisplayObjectContainer(例如 MovieClip 或舞台)都有一个名为 getObjectsUnderPoint 的方法,该方法返回该点下的显示对象数组.它需要一个 Point 对象作为参数.

Any DisplayObjectContainer (such as a MovieClip or the stage) has a method called getObjectsUnderPoint that returns an array of display objects under that point. It takes a Point object as an argument.

var myObjects: Array = stage.getObjectsUnderPoint(new Point(5, 5));

如果你在课堂上使用它,不要忘记导入 flash.geom.Point;

If you are using it in a class don't forget to import flash.geom.Point;

这篇关于Actionscript 3:在像素处获取显示对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆