[]hitArea用法问题
目标:想通过使用 hitArea 来增加按钮的点击区域(有效区向外延伸10px);
结果:使用如下三种写法均不能达到效果,并且关闭按钮也不能关闭(去掉三种写法,点击则可正常关闭);
请指教!
// 写法一
let g:Laya.Graphics = new Laya.Graphics();
g.drawRect(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20,"#FF0000");
let hitA:Laya.HitArea = new Laya.HitArea();
hitA.hit = g;
this.closeBtn.hitArea = hitA;
// 写法二
this.closeBtn.graphics.drawRect(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20,"#FF0000");
let hitA:Laya.HitArea = new Laya.HitArea();
hitA.hit = this.closeBtn.graphics;
this.closeBtn.hitArea = hitA;
// 写法三
let closeRect:Laya.Rectangle = new Laya.Rectangle(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20);
this.closeBtn.hitArea = closeRect;
// closeBtn 为 Laya.Button 实例
this.closeBtn.on(Event.CLICK,this,this.closeWin);
private closeWin():void
{
console.log("the window has closed...");
}
结果:使用如下三种写法均不能达到效果,并且关闭按钮也不能关闭(去掉三种写法,点击则可正常关闭);
请指教!
// 写法一
let g:Laya.Graphics = new Laya.Graphics();
g.drawRect(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20,"#FF0000");
let hitA:Laya.HitArea = new Laya.HitArea();
hitA.hit = g;
this.closeBtn.hitArea = hitA;
// 写法二
this.closeBtn.graphics.drawRect(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20,"#FF0000");
let hitA:Laya.HitArea = new Laya.HitArea();
hitA.hit = this.closeBtn.graphics;
this.closeBtn.hitArea = hitA;
// 写法三
let closeRect:Laya.Rectangle = new Laya.Rectangle(this.closeBtn.x-10,this.closeBtn.y-10,this.closeBtn.width+20,this.closeBtn.height+20);
this.closeBtn.hitArea = closeRect;
// closeBtn 为 Laya.Button 实例
this.closeBtn.on(Event.CLICK,this,this.closeWin);
private closeWin():void
{
console.log("the window has closed...");
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Monica - 知识达人
赞同来自:
比如说往左、往上扩充50像素。应该是Rectangle(-50,-50,w,h)