动态加载资源

Cannot read property 'spriteFrame' of null

proprety属性在编译器界面一定要将资源添加进去。

更新资源时,分两种 

1 SpriteFrame

cc.loader.loadRes(imgName,cc.SpriteFrame,function(error,spriteframe){

sprite.spriteFrame = spriteframe;

})

2 Texture

参考链接 https://blog.csdn.net/qq_37490862/article/details/80939509

cc.loader.load(imgName,funciton(error,texture){

     sprite.spriteFrame = new cc.SpriteFrame(texture);

// sprite.spriteFrame._texture = texture;  不能正确更新,为引用

//sprite.spriteFrame.setTexture(texture); 不能正确更新,为引用

})

猜你喜欢

转载自blog.csdn.net/ChangeNew/article/details/83146988