各位大牛好。想绘制一个带点击事件的圆弧预制体,点击事件不响应

各位大牛好。想绘制一个带点击事件的圆弧预制体,可是点击不起作用。

//下为自定义带点击圆弧预制体,点击事件不响应
const {ccclass, property} = cc._decorator;

@ccclass
export default class Arc extends cc.Component {

// LIFE-CYCLE CALLBACKS:

// onLoad () {}
private context:cc.Graphics;
private btn:cc.Button;

start () {   
}

public draw(x: number, y: number, r: number, startAngle: number, endAngle: number){
    this.context=this.node.getComponent(cc.Graphics);
    this.context.strokeColor=cc.Color.RED;
    this.context.lineWidth=15;
    this.context.arc(x,y, r,startAngle,endAngle,false);
    this.context.stroke();

    var clickEventHandler = new cc.Component.EventHandler();
    clickEventHandler.target = this.node; //这个 node 节点是你的事件处理代码组件所属的节点
    clickEventHandler.component = "Arc";//这个是代码文件名
    clickEventHandler.handler = "btnClick";

    this.btn = this.node.getComponent(cc.Button);
    this.btn.clickEvents.push(clickEventHandler); 
    cc.log(this.btn);
}

btnClick(event){
    cc.log(event.currentTarget)
}

// update (dt) {}

}

以下为调用
let arv=cc.instantiate(this.arc);
arv.getComponent(“Arc”).draw(0,0,10,0,0.25*Math.PI);
this.node.getChildByName(“btn”).addChild(arv);

    let arv2=cc.instantiate(this.arc);
    arv2.getComponent("Arc").draw(0,0,30,0.25*Math.PI,0.5*Math.PI);
    this.node.getChildByName("btn").addChild(arv2);

    let arv1=cc.instantiate(this.arc);
    arv1.getComponent("Arc").draw(0,0,50,0.5*Math.PI,0.75*Math.PI);
    this.node.getChildByName("btn").addChild(arv1);

    let arv3=cc.instantiate(this.arc);
    arv3.getComponent("Arc").draw(0,0,70,0.75*Math.PI,1*Math.PI);
    this.node.getChildByName("btn").addChild(arv3);

效果图,只是触摸点击不响应

是调用的时候定事件,还是定义的时候呢?

大佬们出来支持下哈…

问题已找到,原来是顶节点大小为零导致事件不响应。可我的想法是预制体的大小等于绘制图形的大小,发现做不到啊,这怎么解决呢,大佬们你们在哪?

大佬们,自定义组件的大小如何自适应绘制图形的大小呢?

冒个泡,寻找大佬…

老铁,你最后咋解决