【问题标题】:Detect object over another object as3在另一个物体上检测物体 as3
【发布时间】:2012-06-26 18:19:09
【问题描述】:

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

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

【问题讨论】:

    标签: actionscript-3 flash collision-detection


    【解决方案1】:

    DisplayObject.hitTestObject(obj:DisplayObject):Boolean

    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()

    【讨论】:

    • 正是我需要的,谢谢!我会在 9 分钟内接受你的回答 :)(计时器)
    • 很高兴它有帮助,当我不用认真研究就能回答一个问题时总是很好,祝你好运。
    【解决方案2】:

    您可以通过以下几种方式做到这一点:

    flash.display.DisplayObject.hitTest()

    flash.display.DisplayObject.getRect()

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

    【讨论】:

    • 谢谢!我要使用 flash.display.DisplayObject.hitTest()
    【解决方案3】:

    你可以使用 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/

    【讨论】:

      猜你喜欢
      • 2020-05-21
      • 2023-03-16
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      相关资源
      最近更新 更多