Click event is working only in the circle centre

偶尔善良 提交于 2019-12-24 00:58:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!