简体   繁体   中英

collision detection between graphics and sprite in phaser

this is my 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

  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.

Or skip proper physics and calculate the collisions yourself: check the ball's position against the arc radius and angle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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