1. 从已有sprite加载
this.myPlayer.getComponent(cc.Sprite).spriteFrame = this.iconOff.spriteFrame
2.同步加载
var resUrl = cc.url.raw('resources/icon.jpg')
var texture = cc.textureCache.addImage(resUrl)
node.getComponent(cc.Sprite).spriteFrame.setTexture(texture)
3.异步加载
var url = 'globalUI/myIcon';
var _this = this;
cc.loader.loadRes(url,cc.SpriteFrame,function(err,spriteFrame)
{
_this.myPlayer.spriteFrame = spriteFrame;
});
4.网络加载
var url = "http://localhost:1234/icon";
cc.loader.load({url: url, type: 'png'}, function(err,img){
var myIcon = new cc.SpriteFrame(img);
self.logo.spriteFrame = myIcon;
});