cocos2d 制作光晕特效

cocos2d 制作光晕特效,第1张

概述*********************.h文件********************* #include "cocos2d.h" #include "HelloWorldScene.h" USING_NS_CC; class LightCCSprite : public CCSprite { public: static CCSprite *spriteWithFile(const char *********************.h文件********************* #include "cocos2d.h" #include "HelloWorldScene.h"
USING_NS_CC;
class lightCCSprite : public CCSprite { public: static CCSprite *spriteWithfile(const char * filename); virtual voID draw(); };

****************.cpp文件****************** #include "lightCCSprite.h"
CCSprite *lightCCSprite::spriteWithfile(const char * filename){
CCSprite *pobSprite = new lightCCSprite();//这里才会调用draw,而不是CCSprite的draw
if (pobSprite && pobSprite->initWithfile(filename)) { pobSprite->autorelease(); return pobSprite; } CC_SAFE_DELETE(pobSprite);
return NulL; }

voID lightCCSprite::draw(){

//CCSprite::draw();//如果不取消的话如果两个lightCCSPrite对象只有一个会产生亮光
((HelloWorld*)getParent())->darknessLayer->begin();
CC_PROfileR_START_category(kCCProfilercategorySprit e,"CCSprite - draw");
CCAssert(!m_pobBatchNode,"If CCSprite is being rendered by CCSpriteBatchNode,CCSprite#draw SHOulD NOT be called");
CC_NODE_DRAW_SETUP();

//glClear(GL_color_BUFFER_BIT); glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_Alpha); glcolorMask(0.0f,0.0f,1.0f);//关键句
#define kQuadSize sizeof(m_squad.bl)
if (m_pobTexture!= NulL) { glBindTexture(GL_TEXTURE_2D,m_pobTexture->getname()); } else { glBindTexture(GL_TEXTURE_2D,0); }

// ccGLEnabLevertexAttribs( kCCVertexAttribFlag_PoscolorTex );
long offset = (long)&m_squad; // vertex int diff = offsetof( ccV3F_C4B_T2F,vertices); glVertexAttribPointer(kCCVertexAttrib_position,3,GL_float,GL_FALSE,kQuadSize,(voID*) (offset + diff));
// texCoods diff = offsetof( ccV3F_C4B_T2F,texCoords); glVertexAttribPointer(kCCVertexAttrib_TexCoords,2,(voID*)(offset + diff));
// color diff = offsetof( ccV3F_C4B_T2F,colors); glVertexAttribPointer(kCCVertexAttrib_color,4,GL_UNSIGNED_BYTE,GL_TRUE,(voID*)(offset + diff)); glDrawArrays(GL_TRIANGLE_STRIP,4);

glcolorMask(1.0f,1.0f,1.0f); ((HelloWorld*)getParent())->darknessLayer->end(); } ********************调用处************************* CCSprite *sprite2=lightCCSprite::spriteWithfile("light.png");//继承ccsprite新建对象 sprite2->setposition(ccp(100,200)); this->addChild(sprite2,2); sprite2->runAction(CCRepeatForever::create((CCActionInterval *)CCSequence::create(CCMoveBy::create(3.0f,ccp(300,0)),CCMoveBy::create(0.1f,ccp(-300,NulL)));

darknessLayer = CCRenderTexture::create(size.wIDth,size.height); darknessLayer->setposition(ccp( size.wIDth /2,size.height/2 )); this->addChild(darknessLayer,20); darknessLayer->clear(0,0.5f);//设置黑夜笼罩 *********************最终效果************************

制作光晕特效" name="image_operate_32241410170041285" alt="cocos2d 制作光晕特效" src="http://img.jb51.cc/vcimg/static/loading.png" wIDth="496" height="358" src="http://s2.sinaimg.cn/mw690/003tZB1Hzy6LSOsPlit01&690">

总结

以上是内存溢出为你收集整理的cocos2d 制作光晕特效全部内容,希望文章能够帮你解决cocos2d 制作光晕特效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1024936.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存