0

假设我有两个形状包裹在 Movieclip 容器中。如何检测一种形状是否超过另一种形状?更准确地说,一个形状是否覆盖了其他形状的一部分/全部?

到目前为止,我已经设法通过比较两个形状的坐标来做到这一点,但我想知道是否有一些内置函数或更简单的方法来做到这一点。谢谢

4

3 回答 3

2

DisplayObject.hitTestObject(obj:DisplayObject):布尔值

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject ()

如果您需要更精细的命中测试并愿意使用 BitmapData 对象(您可以使用 BitmapData.draw(dispObj) 将 DisplayObject 绘制到 BitmapData);

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#hitTest ()

于 2012-06-26T18:22:56.403 回答
2

这里有几种方法可以做到这一点:

flash.display.DisplayObject.hitTest()

或者

flash.display.DisplayObject.getRect()

例如: sprite1.getRect(stage).intersects(sprite2.getRect(stage));

于 2012-06-26T18:24:08.507 回答
1

您可以使用 hitTestObject http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject%28%29

trace(shape1.hitTestObject(shape2));

但请记住,如果只是对象的边界重叠,这是一个简单的测试。如果您想要像素完美的碰撞测试,您将不得不使用一些第三方库,例如http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/

于 2012-06-26T18:26:05.567 回答