【问题标题】:pixijs containsPoint and use hitAreapixijs containsPoint 并使用 hitArea
【发布时间】:2023-02-09 01:34:40
【问题描述】:

我想检查精灵的某个区域是否有一个点 但是 containsPoint 方法不包括该区域并检查它是否已满。

        const box = Sprite.from(box2Texture)
        box.anchor.set(0.5, 0.5)
        box.position.set(50, 25)
        box.scale.set(0.3)
        box.hitArea = new Polygon([-50, 0, 0, -25, 50, 0, 0, 25])

【问题讨论】:

    标签: javascript pixi.js


    【解决方案1】:

    默认情况下,DisplayObject 的 hitArea 是未定义的。

    如果您需要使用自定义的 hitArea 来检查是否包含该点,请确保在执行检查之前对其进行初始化。

    否则,如果您不需要任何特殊的 hitArea 处理,您总是可以回退到对象边界进行检查:

    const box = Sprite.from(box2Texture)
    const point = new Point();
    
    box.getBounds().contains(p.x, p.y);
    

    链接到有效的playground

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2016-02-23
      • 2020-12-14
      相关资源
      最近更新 更多