1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- cc.Class({
- extends: cc.Component,
- /* --------------------------------segmentation-------------------------------- */
- onLoad() {
- this.content = this.node.getChildByName("view").getChildByName("content");
- // ------------------事件监听
- this.node.on("scrolling", this._event_update_opacity, this);
- this.content.on(cc.Node.EventType.CHILD_REMOVED, this._event_update_opacity, this);
- this.content.on(cc.Node.EventType.CHILD_REORDER, this._event_update_opacity, this);
- },
- /* ***************功能函数*************** */
- /**获取在世界坐标系下的节点包围盒(不包含自身激活的子节点范围) */
- _get_bounding_box_to_world(node_o_) {
- let w_n = node_o_._contentSize.width;
- let h_n = node_o_._contentSize.height;
- let rect_o = cc.rect(
- -node_o_._anchorPoint.x * w_n,
- -node_o_._anchorPoint.y * h_n,
- w_n,
- h_n
- );
- node_o_._calculWorldMatrix();
- rect_o.transformMat4(rect_o, node_o_._worldMatrix);
- return rect_o;
- },
- /**检测碰撞 */
- _check_collision(node_o_) {
- let rect1_o = this._get_bounding_box_to_world(this.content.parent);
- let rect2_o = this._get_bounding_box_to_world(node_o_);
- // ------------------保险范围
- rect1_o.width += rect1_o.width * 0.5;
- rect1_o.height += rect1_o.height * 0.5;
- rect1_o.x -= rect1_o.width * 0.25;
- rect1_o.y -= rect1_o.height * 0.25;
- return rect1_o.intersects(rect2_o);
- },
- /* ***************自定义事件*************** */
- _event_update_opacity() {
- this.content.children.forEach(v1_o => {
- v1_o.opacity = this._check_collision(v1_o) ? 255 : 0;
- });
- },
- })
|