问题
When I use a circle, only its centre receives the event, if I click anywhere it doesn't work, only when I click in the circle centre. How can I make the whole circle clickable?
const circle = this.add.circle(300, 300, 25, 0xff0000, 1);
circle.setInteractive();
circle.on('pointerdown', function() {
console.log("click");
});
Update: Using phaser 3
回答1:
var config = {
width: 800,
height: 600,
type: Phaser.AUTO,
parent: 'phaser-example',
scene: {
create: create
}
};
var game = new Phaser.Game(config);
function create ()
{
var graphics = this.add.graphics({ fillStyle: { color: 0xff0000 } });
var circle = new Phaser.Geom.Circle(30, 30, 25);
graphics.fillCircleShape(circle);
this.input.on('pointerdown', function (pointer) {
console.log("click")
});
}
<script src="//cdn.jsdelivr.net/npm/phaser@3.17.0/dist/phaser.min.js"></script>
来源:https://stackoverflow.com/questions/56089416/click-event-is-working-only-in-the-circle-centre