ScrollView + Layout 组件完成自动排版

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/85887792

1) 为content加点添加Layout组件

2) Prefab

3)代码

cc.Class({
    extends: cc.Component,

    properties: {
        btn:{
            default: null,
            type: cc.Button
        },
        player_info_prefab:{
            default: null,
            type: cc.Prefab
        },

        scrollview:{
            default: null,
            type: cc.ScrollView
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
     
    },

    // 
    start () {
        for(var i = 0; i < 20; i++){
            var player_info = cc.instantiate(this.player_info_prefab);
            this.scrollview.content.addChild(player_info);
        }
    },

    // update (dt) {},
});

4) 效果

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/85887792
今日推荐