移动器3:重叠时检测XY坐标
我正在尝试检测XY坐标在有对象(子弹)击中时的画布纹理(土地)的重叠。我可以通过使用:object.x and object.y找到对象的位置,但是位置不是画布纹理的重叠位置。 有人有想法吗?谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在尝试检测XY坐标在有对象(子弹)击中时的画布纹理(土地)的重叠。我可以通过使用:object.x and object.y找到对象的位置,但是位置不是画布纹理的重叠位置。 有人有想法吗?谢谢。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
在此处讨论一个可能的解决方案,如果您使用的是Arcade Physics ,请在此处讨论: https://phasser.discourse.group/t/pixelperfect-collision-collision-collision-orment-betest-betest-bet-------- not-pointer/6377
在此处使用一个工作演示:
要点是:使用物理
重叠
函数(文档),在ProcessCallback
function (所说的功能,说的功能如果重叠应触发),请检查“徽标”的像素(在您的情况下)是否可见this.textures.getPixelalpha(x,y,y,logo”)= == 255
()。根据您希望子弹重叠的方式,您必须调整
getPixelalpha
函数的位置(x,y)计算。在上述示例中,球/子弹的中心用于检测重叠。A possible solution, if you are using arcade physics, is discussed here: https://phaser.discourse.group/t/pixelperfect-collision-or-hittest-between-object-and-any-coordinate-not-pointer/6377
With a working demo here: https://codepen.io/samme/pen/JjYYqaZ
The gist is: use the physics
overlap
function (documentation), and in theprocessCallback
function (the function that, says if the overlap should trigger), check if the pixel of the "logo" (in your case the land), is visible or notthis.textures.getPixelAlpha(x, y , "logo") === 255
(documenation).Depending how you want the bullet to overlap, you would have to tweak the position (x, y) calculation for the
getPixelAlpha
function. In the above mentioned example the center of the ball/bullet is used to detect the overlap.