cocos2d js显示远程下载的图片资源
1.远程下载图片函数: cc.textureCache.addImage(address,function(texture){ //todo //3 var spTouXiang = new cc.Sprite(texture); } },this); }
2.会发现,报这样类似的错误: textureCache加载远程图片,在WebGL下失败浏览器; chrome 自动使用的WebGL模式, 执行测试用例:TextureCacheTest.js Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at http://www.cocos2d-x.org/attachments/download/1508may not be loaded. TexturesWebGL.js:467 强制使用canvas renderer显示正常,不过在console中会报跨域的警告 Image from origin 'http://www.cocos2d-x.org' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8081' is therefore not allowed access.
3.经过上述2部,texture正常情况下已经有值了。
然后在上述 //todo //3的位置写上 var spTouXiang = new cc.Sprite(texture); 表示增加一个sprite,然后用从远程下载的texture纹理赋值,并显示 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |