Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

一个List的数组头像地址来设置SpriteFrame

$
0
0

@317156200 写道:

cc.Class({
extends: cc.Component,

properties: {        
    headPic: cc.Sprite,
    nickName: cc.Label,
    geshuNum: cc.Label,
    dianshuNum: cc.Sprite              
},

init: function (data) {        
    this.headPic.Sprite = data.headPic;
    this.nickName.string = data.nickName;        
    this.geshuNum.string = data.geshuNum;
    this.dianshuNum.Sprite = data.dianshuNum;
},

onLoad: function () {

}

});


cc.Class({
extends: cc.Component,
properties: {
itemPrefab:cc.Prefab,
},

onLoad: function () {
    var allCount = 5;
    var datalist = {};    
    var _this = this;

    for (var i = 1; i <= allCount; i++) {

        var imageUrl = cc.url.raw("image/resources/09.png");
        var resutUrl = cc.url.raw("image/resources/20.png");

        var OverList = cc.instantiate(this.itemPrefab);
            this.node.addChild(OverList);

            OverList.getComponent('overlistItem').init({ 
                headPic: _this.getImage(resutUrl),
                nickName: '用户: '+i+'号',
                geshuNum: i,
                dianshuNum: resutUrl 
            });
    }
},

getImage(resutUrl){
    cc.loader.loadResAll("image/resources", function (err, texture) {
        var texture = cc.textureCache.addImage(resutUrl);
        return texture.url;
    });  
}

});

怎么For循环的方式将头像换成不同的图像背景。

帖子: 4

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>