Jump to content

How to detect onClick in Circle graphics ?


kenshero
 Share

Recommended Posts

i use this code

    var circles = this.game.add.graphics(this.game.world.centerX, this.game.world.centerY);
    circles.lineStyle(1, 0x0000ff);
    circles.drawCircle(0, 0, 200); // and finally add the third 1px wide unfilled blue circle with a radius of 150
    circles.inputEnabled = true
    circles.events.onInputDown.add(function(){
      console.log("cire click");
    }, this)

 

but not working. Can i detect click in Circle ?

Link to comment
Share on other sites

To fix the problem of the clicking the rectangle you can check the distance between your click and the center of the circle and compare it to the radius of the circle.

var distanceToCenterOfCircle = Phaser.Math.distance(circle.x, circle.y, pointer.x, pointer.y);
var circleRadius = 100;
if (distanceToCenterOfCircle <= circleRadius){
  // Do click logic.
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...