关于cocos2d-x纹理裁剪的1个问题

huruihappy 2012-02-20 10:12:42
我用cocos2d-x 中的CCTexture2D加载纹理之后,如何实现类似J2ME里面setClip那样的效果。参考了很多资料除了把他弄成Sprite进行裁剪外好像没其他好的办法,但是那样用绘制效率太低了。我只想显示纹理的一部分到屏幕上。

顺便问下,cocos2d里面绘制基础的几何图元如何弄,比如说填充1个半透明的圆角矩形,绘制1个矩形
...全文
681 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Night-Wish 2013-09-09
  • 打赏
  • 举报
回复
void PlayLayer::initClisper(CCSprite *s_hole,CCClippingNode **cliper,int tag){ CCDrawNode*stencil = CCDrawNode::create(); CCPoint rectangle[4]; rectangle[0]= ccp(0, 0); rectangle[1]= ccp(s_hole->getContentSize().width,0); rectangle[2]= ccp(s_hole->getContentSize().width,400); rectangle[3]= ccp(0, 400); //绘制一个矩形 ccColor4F color = {1, 1, 1, 1}; stencil->drawPolygon(rectangle,4, color, 1, color); *cliper = CCClippingNode::create(stencil); (*cliper)->setPosition(s_hole->getPositionX()-s_hole->getContentSize().width/2,s_hole->getPositionY()); (*cliper)->setContentSize(CCSizeMake(stencil->getContentSize().width, 200)); (*cliper)->setTag(tag); this->addChild(*cliper); } 代码如上,主要类CCClippingNode能够实现你所需要的功能,详细如何坐,自己google一下,很多答案,这里重点给你说一下,想要实现效果,你必须改ios目录下appcontroller.mm文件里一个地方 EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] pixelFormat: kEAGLColorFormatRGB565 depthFormat: GL_DEPTH24_STENCIL8_OES preserveBackbuffer: NO sharegroup: nil multiSampling: NO numberOfSamples:0 ]; cocos2d::CCDirector::sharedDirector()->setDepthTest(true); 自己对应下,kEAGLColorFormatRGB565,GL_DEPTH24_STENCIL8_OES,cocos2d::CCDirector::sharedDirector()->setDepthTest(true);
merlinfang 2013-09-04
  • 打赏
  • 举报
回复
cocos2d 2.1提供了sprite新的API,指定区域的,不过还是用opengles来画吧
oO水儿Oo 2012-10-12
  • 打赏
  • 举报
回复
cocos2d里面有opengl ES,用opengl的方法可以绘制图元,详细使用可以自己看看有关opengl的书
oO水儿Oo 2012-10-12
  • 打赏
  • 举报
回复
用CCImage的这个方法初始化一个CCImage,bool initWithImageFile (const char *strPath, EImageFormat imageType=kFmtPng);然后用unsigned char * getData ()方法获得图片的像素指针,用int getDataLen ()获得像素个数,用virtual unsigned short getWidth (void),virtual unsigned short getHeight (void)获得宽和高,然后算一下自己要截取的图片的位置和大小,拷入一个新的char数组里,然后用bool initWithImageData (void *pData, int nDataLen, EImageFormat eFmt=kFmtUnKnown, int nWidth=0, int nHeight=0, int nBitsPerComponent=8)构造一个CCImage实例,用CCImage去构造一个CCTexture就OK了,看API自己想的,没实际操作过
huruihappy 2012-02-21
  • 打赏
  • 举报
回复
没人知道么

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧