性能优化过后的Cocos Creator ScrollView组件

const { ccclass, property } = cc._decorator;



@ccclass

export default class ScrollViewPro extends cc.ScrollView {


    // LIFE-CYCLE CALLBACKS:

    start() {



    }



    onLoad() {

        this.optDC();

        this.node.on('scrolling', this.optDC, this);

    }



    optDC(){

        let self = this;

        let svLeftBottomPt:cc.Vec2 = this.node.parent.convertToWorldSpaceAR(new cc.Vec2(

            self.node.x - self.node.anchorX * self.node.width, self.node.y - self.node.anchorY * self.node.height

        ));



        var viewRect = cc.rect(svLeftBottomPt.x,svLeftBottomPt.y,this.node.width, this.node.height);

        for (let i = 0; i < this.content.children.length; i++) {

            const node = this.content.children[i];

            if (viewRect.intersects(node.getBoundingBoxToWorld())) {

                node.opacity = 255;

            }

            else {

                node.opacity = 0;

            }

        }

    }




    update(dt) {

        

    }

}

简单易懂!

发布了10 篇原创文章 · 获赞 13 · 访问量 602

猜你喜欢

转载自blog.csdn.net/CoderXZ/article/details/105524172