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/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);
spTouXiang.setPosition(x,y);
this.addChild(spTouXiang);