cocos2d-lua ScaleTo函数细节问题

      程序中使用cc.ScaleTo:create(t, scale_x, scale_y, scale_z),如果scale_z设置成0,这是不影响UI的具体显示,但是在对UI进行addTouchEventListener做点击监听时,会不响应点击事件。

后来跟了源码发现,cocos2d再对widget组件做事件监听时有调用:hitTest方法

 if(hitTest(_touchBeganPosition, camera, nullptr))
 {
   if (isClippingParentContainsPoint(_touchBeganPosition)) {
                _hittedByCamera = camera;
                _hitted = true;
   }
 }
hitTest方法主要用于判断触摸点是否在节点范围内。

最后调用到isScreenPointInRect方法:

bool Widget::hitTest(const Vec2 &pt, const Camera* camera, Vec3 *p) const
{
    Rect rect;
    rect.size = getContentSize();
    return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, p);
}
该方法在CCNode中定义是:

this is a helper function, checks a GL screen point is in content rectangle space.
This function convert GL screen point to near and far planes as points Pn and Pf,
then calculate the intersect point P which the line PnPf intersect with content rectangle.

所以它的点击有涉及到摄像机远近点的裁剪问题,我们上面把Z轴的scale写成0,导致widget控件无法响应点击事件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值