cocos2d js显示远程下载的图片资源
来源:互联网 发布:java float 精度 编辑:程序博客网 时间:2024/06/06 07:16
1.远程下载图片函数:
cc.textureCache.addImage(address, function(texture){
if(texture){
//todo
//3
var spTouXiang = new cc.Sprite(texture);
spTouXiang.setPosition(x,y);
m_choiceLayer.addChild(spTouXiang);
}
},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/1508 may 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.
浏览器; chrome
自动使用的WebGL模式,
执行测试用例:TextureCacheTest.js
Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at http://www.cocos2d-x.org/attachments/download/1508 may 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);
spTouXiang.setPosition(x,y);
this.addChild(spTouXiang);
表示增加一个sprite,然后用从远程下载的texture纹理赋值,并显示
0 1
- cocos2d js显示远程下载的图片资源
- cocos2d-X 网络动态下载资源图片
- Cocos2d-JS win32 获取远程图片失败
- cocos2d-js 3.0 显示网络图片
- php下载远程的图片
- 使用cocos2d-x 3.2下载图片资源小例子
- Cocos2d-js 开发记录:图片数据资源等的异步加载
- jsp远程调用资源图片,以附件形式下载
- 关于dedecms无法【下载远程图片和资源】
- dedecms不能下载远程图片和资源方法总结
- 超链接下载远程服务器的ftp资源
- cocos2d-js v3.8 动态加载多张远程图片
- cocos2d 资源图片优化
- cocos2d-x 3.2 物理小游戏教程4 block it 刚体的隐藏和显示 源码资源下载
- 使用Silverlight2的WebClient下载远程图片
- 远程下载图片到本地的方法
- cocos2d-JS 实现 横 竖 屏 显示提示图片效果 !!!!!
- cocos2d-x 下载图片
- iOS中的模糊视图效果
- Scala :foldLeft foldRight min max
- web后台分层详解
- 关于单链表
- 进制转换
- cocos2d js显示远程下载的图片资源
- Java多线程-synchronized关键字
- 截屏方式
- poj3070 Fibonacci
- 《算法竞赛入门经典2ndEdition 》习题3-4 周期串(Periodic Strings, Uva455)
- 异常解决:java.net.ConnectException: Call To Master/127.0.0.1:9000 failed on connection exception
- swift初体验
- iOS-自定义 UITabBarController
- 集群监控之web端动态的显示数据(highchart)