点击事件仅在圈子中心有效 [英] Click event is working only in the circle centre

查看:48
本文介绍了点击事件仅在圈子中心有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用圆时,只有其中心才能接收到该事件,如果单击不起作用的任何地方,则只有在单击圆中心时才可以接收该事件. 如何使整个圈子可点击?

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");
}); 

更新:使用移相器3

推荐答案

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>

这篇关于点击事件仅在圈子中心有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆