cc.loader.load(‘http://116.196.94.22:8081/sss/timg.jpg’, function (err, clip) {
/* var cuip = new cc.Node(‘Sprite’);
self.addChild(cuip);
var sp = cuip.addComponent(cc.Sprite);
sp.spriteFrame =clip ;
cuip.setAnchorPoint(0.5, 0.5);
//cuip.setContentSize(100, 100);
cuip.position = cc.v2(-cuip.width/2, 0);*/
});
我按照api文档为什么会异常
Access to Image at ‘http://116.196.94.22:8081/sss/timg.jpg’ from origin ‘http://localhost:7456’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:7456’ is therefore not allowed access.
http请求跨域
大佬要怎么才能把http资源读进来然后转为Sprite呢?
cc.loader.load('http://116.196.94.22:8081/sss/timg.jpg', function (err, clip) {
// 这里的clip 是 texture类型 你不能当成spriteFrame用
// 所以 sp.spriteFrame = clip ; 这句改成
sp.spriteFrame = new cc.SpriteFrame(clip);
});
文档:
http://docs.cocos.com/creator/manual/zh/scripting/load-assets.html#加载远程资源和设备资源
web端存在跨域问题 请自行解决
1赞