【问题标题】:Click event is working only in the circle centre点击事件仅在圆心有效
【发布时间】:2019-09-29 01:27:09
【问题描述】:

当我使用一个圆圈时,只有它的中心接收事件,如果我点击任何它不起作用的地方,只有当我点击圆圈中心时。 如何让整个圈子都可以点击?

const circle = this.add.circle(300, 300, 25, 0xff0000, 1);
circle.setInteractive();
circle.on('pointerdown', function() {
    console.log("click");
}); 

更新:使用移相器 3

【问题讨论】:

  • Phaser 2 CE 或 Phaser 3 ?
  • Phaser 3 ......

标签: phaser-framework


【解决方案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>

【讨论】:

    猜你喜欢
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    相关资源
    最近更新 更多