cocos3.10 html 关于sprite 未加载的时候显示白色的问题
来源:互联网 发布:淘宝视频拍摄手机软件 编辑:程序博客网 时间:2024/06/05 04:40
在做游戏的项目中,发现游戏图片未下载下来,或者正在下载中,显示为白色。
查看了引擎源码,在CCSprite.js中的setTexture函数中 分析一下
1、如果纹理不存在就在设置渲染命令中的纹理为空
2、如果能找到纹理的名字,就添加到纹理缓存里面,
3、根据纹理是否加载来处理,如果纹理竞价加载,那就直接设置纹理到渲染命令中,如果纹理未加载,就设置渲染命令中的纹理为空,就是
this._renderCmd._setTexture(null);这句,然后监听纹理加载事件,加载完毕重新设置纹理。
setTexture:function (texture) {
if(!texture)
returnthis._renderCmd._setTexture(null);
//CCSprite.cpp 327 and 338
var isFileName = cc.isString(texture);
if(isFileName)
texture =cc.textureCache.addImage(texture);
if(texture._textureLoaded){
this._setTexture(texture,isFileName);
this.setColor(this._realColor);
this._textureLoaded = true;
}else{
this._renderCmd._setTexture(null);
texture.addEventListener("load",function(){
this._setTexture(texture,isFileName);
this.setColor(this._realColor);
this._textureLoaded = true;
}, this);
}
},
2、
因为如果把纹理设置为空,会运行,_updateBlendFunc(),其中如果纹理不存在,就会把
blendFunc.src= cc.SRC_ALPHA;并且在渲染的时候会根据这个值来渲染,就会表现为白色
proto._updateBlendFunc= function () {
if (this._batchNode) {
cc.log(cc._LogInfos.Sprite__updateBlendFunc);
return;
}
// it's possible to have an untexturedsprite
var node = this._node,
blendFunc = node._blendFunc;
if (!node._texture ||!node._texture.hasPremultipliedAlpha()) {
if (blendFunc.src === cc.ONE&& blendFunc.dst === cc.BLEND_DST) {
blendFunc.src = cc.SRC_ALPHA;
}
node.opacityModifyRGB = false;
} else {
if (blendFunc.src === cc.SRC_ALPHA&& blendFunc.dst === cc.BLEND_DST) {
blendFunc.src = cc.ONE;
}
node.opacityModifyRGB = true;
}
};
3、修改方案,
在CCSprite.js 554行把this._renderCmd._setTexture(null);改为this._renderCmd._setTexture(texture);
在纹理存在且没有加载成功的时候是不会渲染的
proto.rendering= function (ctx) {
var node = this._node, locTexture =node._texture;
if ((locTexture&&!locTexture._textureLoaded) || this._displayedOpacity === 0)
return;
4、再次修改
if (this._batchNode) { cc.log(cc._LogInfos.Sprite__updateBlendFunc); return;}/** * 2017-6-17修改混合算法,注释了原来的算法 */var node = this._node;if(node._texture && node._texture.hasPremultipliedAlpha()){ node._blendFunc.src = cc.BLEND_SRC; node._blendFunc.dst = cc.BLEND_DST; node.opacityModifyRGB = true;}else{ node._blendFunc.src = cc.SRC_ALPHA; node._blendFunc.dst = cc.ONE_MINUS_SRC_ALPHA; node.opacityModifyRGB = false;}
- cocos3.10 html 关于sprite 未加载的时候显示白色的问题
- cocos3.10 html widget不能显示的错误
- 未解决的问题:log4j总是在加载的时候
- Cocos2D精灵纹理无法加载(显示白色方块)的问题,求解!
- sprite遇到的一个慢慢显示问题
- 关于Android Notification Bar icon setSmallIcon 显示为白板或白色的问题
- 关于Android加载HTML页面中的图片显示问题的解决办法
- 关于一个cocos3.x的优化
- 关于tomcat启动时候界面显示信息的问题
- HTML+CSS基础 img标签alt属性 当图片加载失败的时候显示为文本
- webView显示网页的时候,右半部分有白色一片空白区域
- (iOS开发)当tableView数据较少的时候,隐藏下面,并显示白色
- 关于youku嵌入式播放器浏览器白色边框的问题
- ios 加载本地HTML文件,图片不显示的问题
- 解决popwindow在窗体未加载完成时候显示报错问题
- android progressBar 加载内容的时候显示
- html显示xml数据的时候
- 关于cocos3.3移植android后清空UserDefault.xml数据的问题
- shell脚本编写思路和实例讲解
- 用一篇文章总结Javascript
- js中常用的输入方法
- docker 数据映射
- Leetcode:Combinations
- cocos3.10 html 关于sprite 未加载的时候显示白色的问题
- 在 Windows 上进行 Laravel Homestead 安装、配置及测试
- js如何准确获取当前页面url网址信息
- Win7系统更新显卡后花屏怎么办?Win7系统更新显卡后花屏怎么办?
- 【SQL工具】SQL调优和诊断神器SQLTXPLAIN (SQLT)简介
- 机器人技术(1)基于ROS的机器人底盘AtdRobot
- 函数分类,HIVE CLI命令,简单函数,聚合函数,集合函数,特殊函数(窗口函数,分析函数,混合函数,UDTF),常用函数Demo
- 文章标题
- 2017年计蒜客比赛复赛B D两题