当前位置: 首页 > news >正文

网站开发服务计入什么科目/网站页面优化方法

网站开发服务计入什么科目,网站页面优化方法,做banner网站,北京公司网站设计电话本文转载自 cocos2d-x里的TiledMap出现黑线和抖动的解决方案(不影响其他类使用) 今天搞tiled map发现黑边,开始认为是反锯齿问题,但发现无论开启与否都有边,只是程度不同而已。简单网上搜了下发现有解决方案是 修改ccc…

本文转载自 cocos2d-x里的TiledMap出现黑线和抖动的解决方案(不影响其他类使用)

 

今天搞tiled map发现黑边,开始认为是反锯齿问题,但发现无论开启与否都有边,只是程度不同而已。简单网上搜了下发现有解决方案是 修改ccconfig.h让

#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
同时开启tile图块texture的反锯齿避免抖动。
 
但简单看了下CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL, 发现对texture coordinates作了圈限制。
这是原始的注释:
If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.origin.x*2+1) / (texture.wide*2);
- texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2);
 
The same for bottom and top.
 
This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
 
Affected nodes:
- CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXTiledMap
- CCLabelAtlas
- CCQuadParticleSystem
- CCTileMap
 
可见影响了全部CCSprite,事实也发现Sprite只要使用的贴图是紧贴边的,周围都有可能都被切掉了一部分。
其实你只要解决tilemap的显示问题,就没必要去动到别的类。简单看了下加载tiledmap相关源码,其实只需很小改动。
 
首先不要改CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL, 让它仍然是0.
知道的是tiledmap显示部分要用到CCSprite,但这个CCSprite要CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL开启时的作用, 所以这里要新建个CCSprite的子类CCSpriteTileMap。
 
class CCSpriteTileMap : public CCSprite 
{
protected:
virtual void setTextureCoords(CCRect rect);
};
 
void CCSpriteTileMap::setTextureCoords( CCRect rect )
{
rect = CC_RECT_POINTS_TO_PIXELS(rect);
CCTexture2D *tex = m_pobBatchNode ? m_pobTextureAtlas->getTexture() : m_pobTexture;
if (! tex)
{
return;
}
float atlasWidth = (float)tex->getPixelsWide();
float atlasHeight = (float)tex->getPixelsHigh();
float left, right, top, bottom;
if (m_bRectRotated)
{
#if 1//CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
left    = (2*rect.origin.x+1)/(2*atlasWidth);
right    = left+(rect.size.height*2-2)/(2*atlasWidth);
top        = (2*rect.origin.y+1)/(2*atlasHeight);
bottom    = top+(rect.size.width*2-2)/(2*atlasHeight);
#else
left    = rect.origin.x/atlasWidth;
right    = (rect.origin.x+rect.size.height) / atlasWidth;
top        = rect.origin.y/atlasHeight;
bottom    = (rect.origin.y+rect.size.width) / atlasHeight;
#endif // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
if (m_bFlipX)
{
CC_SWAP(top, bottom, float);
}
if (m_bFlipY)
{
CC_SWAP(left, right, float);
}
m_sQuad.bl.texCoords.u = left;
m_sQuad.bl.texCoords.v = top;
m_sQuad.br.texCoords.u = left;
m_sQuad.br.texCoords.v = bottom;
m_sQuad.tl.texCoords.u = right;
m_sQuad.tl.texCoords.v = top;
m_sQuad.tr.texCoords.u = right;
m_sQuad.tr.texCoords.v = bottom;
}
else
{
#if 1//CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
left    = (2*rect.origin.x+1)/(2*atlasWidth);
right    = left + (rect.size.width*2-2)/(2*atlasWidth);
top        = (2*rect.origin.y+1)/(2*atlasHeight);
bottom    = top + (rect.size.height*2-2)/(2*atlasHeight);
#else
left    = rect.origin.x/atlasWidth;
right    = (rect.origin.x + rect.size.width) / atlasWidth;
top        = rect.origin.y/atlasHeight;
bottom    = (rect.origin.y + rect.size.height) / atlasHeight;
#endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
if(m_bFlipX)
{
CC_SWAP(left,right,float);
}
if(m_bFlipY)
{
CC_SWAP(top,bottom,float);
}
m_sQuad.bl.texCoords.u = left;
m_sQuad.bl.texCoords.v = bottom;
m_sQuad.br.texCoords.u = right;
m_sQuad.br.texCoords.v = bottom;
m_sQuad.tl.texCoords.u = left;
m_sQuad.tl.texCoords.v = top;
m_sQuad.tr.texCoords.u = right;
m_sQuad.tr.texCoords.v = top;
}
}
CCTileMapAtlas.cpp里
CCTileMapAtlas::updateAtlasValueAt 函数中将CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL强行开启
#if 1//CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
float left        = (2 * row * itemWidthInPixels + 1) / (2 * textureWide);
float right       = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide);
float top         = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh);
float bottom      = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh);
#else
float left        = (row * itemWidthInPixels) / textureWide;
float right       = left + itemWidthInPixels / textureWide;
float top         = (col * itemHeightInPixels) / textureHigh;
float bottom      = top + itemHeightInPixels / textureHigh;
#endif
然后找到CCTMXLayer类里面申请new CCSprite的地方替换成new CCSpriteTileMap就OK了。
发现有两处,在这两个函数内
CCTMXLayer::reusedTileWithRect
CCTMXLayer::tileAt
完工!重新BUILD,就看不见恶心的黑线了,同时也不影响别的类使用。
想想如果cocos2d出CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL这个定义最初目的是为了解决tiledmap显示问题的话,为什么不独立出一个针对tiledmap显示问题的编译项呢?当然还有其他目的就另当别论了。
注明下笔者用的cocos2d-x版本是2.1.5,其实2.0.0后版本应该都适用

转载于:https://www.cnblogs.com/cg-Yun/articles/4380316.html

http://www.lbrq.cn/news/1108405.html

相关文章:

  • 哪里有做营销型网站的公司/公司网络推广该怎么做
  • 海南网站制作/seo技术顾问阿亮
  • 广告网站设计公司 作用/学电商出来一般干什么工作
  • 十五种网络营销工具/seo臻系统
  • fuzzz的wordpress模板/高平网站优化公司
  • 最好的免费网站空间/河北seo基础知识
  • 桂林手机网站制作/常用的seo网站优化排名
  • 高端电子商务网站建设/b2b平台网站
  • 扁平化中文网站模板下载/搜索引擎推广的关键词
  • 怎样用电脑和网訨自己做网站/南宁网络优化seo费用
  • 石家庄做网站wsjz/7个湖北seo网站推广策略
  • 学做网站看那个网/搜索关键词的工具
  • 娄底网站建设建站/百度seo排名优化价格
  • 网站建设的目标人群是什么/商丘关键词优化推广
  • 外国人学做中国菜的网站/搜全网的浏览器
  • 百度搜索排名查询/seo网站优化推广
  • 北京建网站软件/网站点击量查询
  • 吉林省建设招标网站/深圳市网络seo推广平台
  • 企业做营销型网站/山东百度推广代理商
  • 做一个购物网站价格/东营优化公司
  • 网站连接怎么做/企业网站建设门户
  • 最便宜的购物app/枫林seo工具
  • 沈阳唐朝网站建设/网络营销公司排行榜
  • 老外做汉字网站/品牌互动营销案例
  • 揭阳seo快速排名/新网站 seo
  • dz插件网站和自己做的网站区别/网站制作多少钱
  • 网站建设开发方式/广告文案
  • 服装网站建设目的作用是什么/代写文章多少钱
  • 网站程序是什么意思/自媒体是什么
  • 沈阳优化网站关键词/竞价托管外包代运营
  • 零基础学习性能测试第二章-linux服务器监控:网络iftop
  • 物联网系统中-告警配置功能的定义
  • Node.js:EventEmitter、Buffer
  • 力扣经典算法篇-26-长度最小的子数组(暴力求解法,左右指针法)
  • OpenCV 官翻6 - Computational Photography
  • 群晖中相册管理 immich大模型的使用