简体   繁体   English

移相器中图形与精灵之间的碰撞检测

[英]collision detection between graphics and sprite in phaser

this is my jsfiddle : http://jsfiddle.net/mrLt1swj/1/ 这是我的jsfiddle: http : //jsfiddle.net/mrLt1swj/1/

what i did basically is creating an empty sprite and append the arc as it's child like this : 我所做的基本上是创建一个空的精灵,并将弧形附加为孩子,如下所示:

paddle = graphics2.arc(0, 0, 110, game.math.degToRad(0), game.math.degToRad(45), false);
paddleSprite = game.add.sprite(0, 0);
game.physics.enable(paddleSprite, Phaser.Physics.ARCADE);
paddleSprite.anchor.set(0.5);
// Add the graphics to the sprite as a child
paddleSprite.addChild(paddle);

in this case i can use the physics on the arc , but the problem here is that the arc is basically a polygon shape, second the position of the sprite is at 0,0 and the arc have different coordinate so the collision will not work if the ball hit the arc instead it will work if it hit the empty sprite 在这种情况下,我可以在圆弧上使用物理原理,但是这里的问题是圆弧基本上是多边形,其次是精灵的位置为0,0 ,圆弧具有不同的坐标,因此如果球击中弧线,如果击中了空的精灵,它将起作用

  1. how can i set the collision bound of the arc so the collision between the ball and the arc work 我如何设置圆弧的碰撞范围,以便球和圆弧之间的碰撞起作用
  2. is there any possible solution where i can set physics to arc and not use the sprite 有没有可能将物理场设置为弧形而不使用精灵的解决方案

For polygon (non-rectangular) collisions you have to use P2 physics instead of Arcade physics. 对于多边形(非矩形)碰撞,您必须使用P2物理而不是Arcade物理。

Or skip proper physics and calculate the collisions yourself: check the ball's position against the arc radius and angle. 或者跳过适当的物理过程,自己计算碰撞:对照弧半径和角度检查球的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM