cocos2dx吸蓝效果实现opengl绘制

前端之家收集整理的这篇文章主要介绍了cocos2dx吸蓝效果实现opengl绘制前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

cocos2dx 想做一些比较炫的效果,单纯依靠引擎封装提供的一些东西毕竟有限,最近项目是用opengl绘制一些效果出来,代码如下:

封装类效果

GoodDropEffects.h文件

#ifndef __GOODBLOOD_H__
#define __GOODBLOOD_H__
#include "cocos2d.h"
#include "global.h"
USING_NS_CC;
 


class GoodsTail:public CCNode
{
public:
	~GoodsTail();
	GoodsTail(){};
	void draw();
	CREATE_FUNC(GoodsTail)
		bool init();
	void onDraw();
	void setOrigin(CCPoint pos);
	void tempfunc(float x1,float y1,float x2,float y2,float d,float &x3,float &y3,float &x4,float &y4);

	Vertex trackpt[101];
	std::vector<GLushort> tiarr;
	Vec3 color;
	GLuint vertexBuffer;
	GLuint indexBuffer;
	std::vector<Vertex> varray;
	CCNode *target;
	void setTarget(CCNode* nd);
};

class GoodDropEffects:public CCNode
{
public:
	~GoodDropEffects();
	GoodDropEffects();
	static GoodDropEffects* create(CCNode* parent,int kinds,int droptype,int color,int side,CCPoint pos)  //side 0 左边 1右边
	{ 
		GoodDropEffects *pRet = new GoodDropEffects(); 
		if (pRet && pRet->init(parent,kinds,droptype,color,side,pos)) 
		{ 
			pRet->autorelease(); 
			parent->addChild(pRet,100);
			return pRet; 
		} 
		else 
		{ 
			delete pRet; 
			pRet = NULL; 
			return NULL; 
		} 
	}
	bool init(CCNode* parent,CCPoint pos);
 
	void PlayEffect(CCPoint src,CCPoint dst);
	void AbsorbEffect(float dt);

 
	CCSprite *m_GoodsSp;
	long m_sides;

	CCPoint m_pos;

	GoodsTail *tail[8];
	CCParticleSystemQuad* ps[4];
	CCSprite *lspr[4];

	void callback3(CCNode* sender,void* data);

	void InitTail(float r,float g,float b);
	CCNode* m_parent;
	char goodsnamestr[100];
};


#endif

GoodDropEffects.ccp文件
#include "GoodDropEffects.h"
#include "SimpleAudioEngine.h"
#include "Characters/Robot.h"
#include "Equipment/crystal.h"
#include "Equipment/EquipBase.h"
#include "Common/EnterStageDataExchange.h"
using namespace CocosDenshion;
 

void GoodsTail::draw()
{
	onDraw();
	//CCNode::draw();
}
void GoodsTail::tempfunc(float x1,float &y4)
{
	if(y1-y2==0)
	{
		x3=x4=x2;
		if(x2==x1)
		{
			y3=y2;
			y4=y2;
			return ;
		}
		else if(x2>x1)
		{
			d=-fabsf(d);
		}
		else d=fabsf(d);
		y3=y2-d;
		y4=y2+d;
		return ;
	}
	float k=0;
	if(x1-x2==0)
	{
		k=0;
	}
	else
	{
		k=-(x1-x2)/(y1-y2);
	}

	if(y2>y1)
	{
		d=fabsf(d);
	}
	else d=-fabsf(d);

	{
		x3=-d/sqrt(k*k+1)+x2;
		y3=-k*d/sqrt(k*k+1)+y2;

		x4=d/sqrt(k*k+1)+x2;
		y4=k*d/sqrt(k*k+1)+y2;
	}
}
void GoodsTail::onDraw()
{    
	float d=0;
	for(int i=0;i<20;++i)
	{
		trackpt[i].Position[0]=trackpt[i+1].Position[0];
		trackpt[i].Position[1]=trackpt[i+1].Position[1];
	} 
	CCPoint pos;
	if(target==0)
	  pos=getPosition();
	else
	  pos=target->getPosition();
	trackpt[20].Position[0]=pos.x;  trackpt[20].Position[1]=pos.y;
	
	float maxdis=ccpDistance(CCPoint(trackpt[0].Position[0],trackpt[0].Position[1]),CCPoint(trackpt[20].Position[0],trackpt[20].Position[1]));
	maxdis=20;
	std::vector<Vertex> ttt;
	tiarr.clear();
	 for(int i=0;i<=20;++i)
	 {
		 if(d==0)
		 {
			 ttt.push_back(trackpt[i]);
		 }
		 else
		 {
			 float x3,y3,x4,y4;
			 if(trackpt[i].Position[0]==trackpt[20].Position[0])
			 {
				 d=0;
			 }
			 tempfunc(trackpt[i-1].Position[0],trackpt[i-1].Position[1],trackpt[i].Position[0],trackpt[i].Position[1],d,x3,y4);
			 Vertex vt1={{x3,0},{color.x,color.y,color.z,{1,0}};
			 Vertex vt2={{x4,y4,0}};
             
			 if(trackpt[i].Position[0]==trackpt[20].Position[0])
			 {
				 vt1.Color[3]=0;
				 vt2.Color[3]=0;
			 }
			 trackpt[i].Color[0]=color.x;
			 trackpt[i].Color[1]=color.y;
			 trackpt[i].Color[2]=color.z;
			 ttt.push_back(vt1); ttt.push_back(trackpt[i]); ttt.push_back(vt2);
			 if(i-1==0)
			 {
				 tiarr.push_back(0);
				 tiarr.push_back(1);
				 tiarr.push_back(2);
				 tiarr.push_back(0);
				 tiarr.push_back(2);
				 tiarr.push_back(3);
			 }
			 else
			 {
				 int imax=3*i;
				 tiarr.push_back(imax-4);  tiarr.push_back(imax-3); tiarr.push_back(imax-1);
				 tiarr.push_back(imax-3);  tiarr.push_back(imax-1); tiarr.push_back(imax);
				 tiarr.push_back(imax-4);  tiarr.push_back(imax-5); tiarr.push_back(imax-2);
				 tiarr.push_back(imax-4);  tiarr.push_back(imax-2); tiarr.push_back(imax-1);
			 }
		 }
		 /*if(i>13)
			 d-=((float)i-13+1)*maxdis*0.001;
		 else*/
			 d+=((float)i+1)*maxdis*0.001;
	 }
    glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	CCGLProgram* pg=CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor);
	pg->use();
	pg->setUniformsForBuiltins();
	
	glBindBuffer(GL_ARRAY_BUFFER,vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER,sizeof(Vertex)*ttt.size(),ttt.data(),GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(GLushort)*tiarr.size(),tiarr.data(),GL_STATIC_DRAW);
	
	GLint _positionLocation = glGetAttribLocation(pg->getProgram(),"a_position");
	GLint _colorLocation = glGetAttribLocation(pg->getProgram(),"a_color");
	glEnableVertexAttribArray(_positionLocation);
	glEnableVertexAttribArray(_colorLocation);
	glVertexAttribPointer(_positionLocation,3,GL_FLOAT,GL_FALSE,sizeof(Vertex),(GLvoid*)offsetof(Vertex,Position));
	glVertexAttribPointer(_colorLocation,4,Color));
	glDrawElements(GL_TRIANGLES,tiarr.size(),GL_UNSIGNED_SHORT,0);
	glBindBuffer(GL_ARRAY_BUFFER,0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
	glDisable(GL_DEPTH_TEST);
}
void GoodsTail::setOrigin(CCPoint pos)
{
	for(int i=0;i<=20;++i){
		trackpt[i].Position[0]=pos.x;
		trackpt[i].Position[1]=pos.y;
	}
	//setPosition(pos);
}
void GoodsTail::setTarget(CCNode* nd)
{
	target=nd;
	CCPoint pos=target->getPosition();
	setOrigin(pos);
	//nd->addChild(this,-1);
}
GoodsTail::~GoodsTail()
{
	glDeleteBuffers(1,&vertexBuffer);
	glDeleteBuffers(1,&indexBuffer);
}
bool GoodsTail::init()
{
	glGenBuffers( 1,&vertexBuffer );
	glGenBuffers( 1,&indexBuffer );
	for(int i=0;i<=20;++i){
		trackpt[i].Position[0]=0;
		trackpt[i].Position[1]=0;
		trackpt[i].Position[2]=0;
		trackpt[i].Color[0]=0;
		trackpt[i].Color[1]=0;
		trackpt[i].Color[2]=1;
		trackpt[i].Color[3]=(float)i/30.0;
		//if(i==20) trackpt[i].Color[3]=0;
		trackpt[i].TexCoord[0]=0;
		trackpt[i].TexCoord[1]=0;
	}
	color=Vec3(0,1,1);
	target=0;
	return true;
}
GoodDropEffects::GoodDropEffects()
{
	m_GoodsSp=NULL;
}
GoodDropEffects::~GoodDropEffects()
{

	if(m_GoodsSp)
	 m_GoodsSp->removeAllChildrenWithCleanup(true);

	 
	for(int i=0;i<4;++i)
	{
		if(tail[i])
		tail[i]->removeFromParentAndCleanup(true);
		
	}
	for(int j=0;j<4;j++)
	{
		if(lspr[j])
		{
			lspr[j]->setVisible(false);
			//lspr[j]->removeFromParentAndCleanup(true);
		}
	}
	ps[0]->removeFromParentAndCleanup(true);
}
 
void GoodDropEffects::PlayEffect(CCPoint src,CCPoint dst)
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();


	

	if(m_sides==1)
	{
		//CCSprite *m_GoodsDrop_R=(CCSprite*)getTag()
		//	CCMenu *menu=(CCMenu*)this->getChildByTag(111);
	 
		m_GoodsSp->setVisible(true);
		//m_GoodsDrop_R->setScaleX(0.6);

		float sx=m_GoodsSp->getPositionX();
		float sy=m_GoodsSp->getPositionY();
		m_GoodsSp->setAnchorPoint(ccp(0.5,0.5));
		sx=m_pos.x,sy=m_pos.y;
		long rand_dir=random_range(1,2);
		rand_dir=1;
		if(rand_dir==1)
		{
		
			long posxmax=random_range(200,280);

			//抛物线轨迹
			ccBezierConfig bezier1;
			bezier1.controlPoint_1 = ccp(sx+50,sy+100);
			bezier1.controlPoint_2 = ccp(sx+150,sy+250);
			bezier1.endPosition = ccp(sx+posxmax,sy+30);


			CCActionInterval*  bezierTo1 = CCBezierTo::create(0.5f,bezier1);    
			CCActionInterval* bezierTo1_ease_in1 = CCEaseIn::create(bezierTo1,6.5); 
			CCRotateBy *rotate1=CCRotateBy::create(0.4f,720);
			CCFiniteTimeAction* seq_action=CCSequence::create(CCSpawn::create(bezierTo1,rotate1,NULL),CCDelayTime::create(0.3),//CCCallFunc::create(this,callfunc_selector(GameLogic::Weapons_DropGuangxiao_R)),NULL);	 
			m_GoodsSp->runAction(seq_action);

		}




	}

	if(m_sides==0)
	{


	 

		m_GoodsSp->setVisible(true);

		float sx=m_GoodsSp->getPositionX();
		float sy=m_GoodsSp->getPositionY();
		m_GoodsSp->setAnchorPoint(ccp(0.5,0.5));
		sx=480-60,sy=250;
		sx=m_pos.x,2);
		rand_dir=2;


		if(rand_dir==2)
		{	 

			long posxmax=random_range(200,280);

			ccBezierConfig bezier2;
			bezier2.controlPoint_1 = ccp(sx-50,sy+100);
			bezier2.controlPoint_2 = ccp(sx-150,sy+250);
			bezier2.endPosition = ccp(sx-posxmax,sy+30);

			CCActionInterval*  bezierTo2 = CCBezierTo::create(0.5f,bezier2);    
			CCActionInterval* bezierTo1_ease_in2 = CCEaseIn::create(bezierTo2,3.5); 
			CCRotateBy *rotate2=CCRotateBy::create(0.4f,-720);
			CCFiniteTimeAction* seq_action2=CCSequence::create(CCSpawn::create(bezierTo2,rotate2,callfunc_selector(GameLogic::Weapons_DropGuangxiao_L)),NULL);
			m_GoodsSp->runAction(seq_action2);
			m_GoodsSp->setRotation(-90);




		}

	}
	scheduleOnce(schedule_selector(GoodDropEffects::AbsorbEffect),1.5);

}


void GoodDropEffects::AbsorbEffect(float dt)
{
	if(m_sides==1)
	{



		if(m_GoodsSp)
			m_GoodsSp->setVisible(true);
		//	m_GoodsDrop_R->setScaleX(0.6);

		float sx=m_GoodsSp->getPositionX();
		float sy=m_GoodsSp->getPositionY();
		m_GoodsSp->setAnchorPoint(ccp(0.5,0.5));


		long rand_dir=random_range(1,2);
		rand_dir=1;
		if(rand_dir==1)
		{

			//sx=480+60;
		//	sy=270;

			//抛物线轨迹
			ccBezierConfig bezier1;
			bezier1.controlPoint_1 = ccp(sx,sy);
			bezier1.controlPoint_2 = ccp(sx-130,sy+80);
			bezier1.endPosition = ccp(480,250);


			CCActionInterval*  bezierTo1 = CCBezierTo::create(0.4f,6.5); 
			CCRotateBy *rotate1=CCRotateBy::create(0.26f,-1440);
			CCFiniteTimeAction* seq_action=CCSequence::create(CCSpawn::create(bezierTo1,CCScaleTo::create(0.4,0.1),CCHide::create(),NULL);	
			m_GoodsSp->setScale(0);
			m_GoodsSp->runAction(seq_action);

		}

	}
	if(m_sides==0)
	{

		//CCSprite *GoodsDrop_L=(CCSprite*)pLayer->getChildByTag(100);
		//GoodsDrop_L->setVisible(true);

		float sx=m_GoodsSp->getPositionX();
		float sy=m_GoodsSp->getPositionY();
		m_GoodsSp->setAnchorPoint(ccp(0.5,0.5));

		long rand_dir=random_range(1,2);
		rand_dir=2;


		if(rand_dir==2)
		{	 

		//	sx=480-60;
		//	sy=270;


			ccBezierConfig bezier2;
			bezier2.controlPoint_1 = ccp(sx,sy);
			bezier2.controlPoint_2 = ccp(sx+130,sy+80);
			bezier2.endPosition = ccp(480,250);

			CCActionInterval*  bezierTo2 = CCBezierTo::create(0.4f,3.5); 
			CCRotateBy *rotate2=CCRotateBy::create(0.26f,-1440);
			CCFiniteTimeAction* seq_action2=CCSequence::create(CCSpawn::create(bezierTo2,NULL);
			m_GoodsSp->setScale(0);
		   m_GoodsSp->runAction(seq_action2);
			m_GoodsSp->setRotation(-90);




		}


	}



	//return ;
	CCPoint src=m_GoodsSp->getPosition();
    CCPoint dst=ccp(480,230);

	SimpleAudioEngine::sharedEngine()->playEffect("SuckBlood1.ogg");
	struct  timeval  now;
	gettimeofday(&now,NULL); 
	srand(now.tv_usec+now.tv_sec*1000000);

	ccBezierConfig bezier;  
	CCPoint pt;
	bezier.controlPoint_1 = ccp(src.x+20-rand()%200,src.y-rand()%500);  
	bezier.controlPoint_2 = ccp(dst.x-100-rand()%200,dst.y-rand()%150);   
	bezier.endPosition = ccp(dst.x,dst.y);  
	pt=ccp(src.x+rand()%50,src.y+rand()%50);
	tail[0]->setOrigin(pt);
	tail[0]->stopAllActions();
	//tail[0]->runAction(CCSequence::create(CCDelayTime::create(0.01),CCBezierTo::create(0.4,bezier),CCCallFuncND::create(this,callfuncND_selector(SuckBlood::callback3),(void*)0),0));
	lspr[0]->setPosition(pt);
	lspr[0]->stopAllActions();
	lspr[0]->setScale(0.01);
	lspr[0]->runAction(CCSequence::create(CCDelayTime::create(0.035),CCSpawn::create(CCBezierTo::create(0.65,CCScaleTo::create(0.3,0),0));
	tail[0]->setTarget(lspr[0]);
	bezier.controlPoint_1 = ccp(src.x+40,src.y-rand()%450);  
	bezier.controlPoint_2 = ccp(dst.x,dst.y);  
	pt=ccp(src.x-rand()%50,src.y-rand()%50);
	tail[1]->setOrigin(pt);
	tail[1]->stopAllActions();
	//tail[1]->runAction(CCSequence::create(CCDelayTime::create(0.055),CCBezierTo::create(0.6,0));

	lspr[1]->setPosition(pt);
	lspr[1]->stopAllActions();
	lspr[1]->setScale(0.01);
	lspr[1]->runAction(CCSequence::create(CCDelayTime::create(0.055),0));
	tail[1]->setTarget(lspr[1]);
	bezier.controlPoint_1 = ccp(src.x+50,src.y+rand()%650);  
	bezier.controlPoint_2 = ccp(dst.x-rand()%100,dst.y+rand()%150);   
	bezier.endPosition = ccp(dst.x,dst.y);  
	pt=ccp(src.x+50,src.y-rand()%40);
	
	
	tail[2]->setOrigin(pt);
	tail[2]->stopAllActions();
	//tail[2]->runAction(CCSequence::create(CCDelayTime::create(0.02),CCBezierTo::create(0.5,0));

	lspr[2]->setPosition(pt);
	lspr[2]->stopAllActions();
	lspr[2]->setScale(0.01);
	lspr[2]->runAction(CCSequence::create(CCDelayTime::create(0.025),0));
	tail[2]->setTarget(lspr[2]);



	bezier.controlPoint_1 = ccp(src.x,src.y+rand()%590);  
	bezier.controlPoint_2 = ccp(dst.x,src.y+rand()%40);
	tail[3]->setOrigin(pt);
	tail[3]->stopAllActions();
	//tail[3]->runAction(CCSequence::create(CCBezierTo::create(0.3,0));

	lspr[3]->setPosition(pt);
	//lspr[3]->stopAllActions();
	lspr[3]->setScale(1);
	CCRotateBy *rotate1=NULL;
	if(m_sides==0)
	 rotate1=CCRotateBy::create(0.5f,720);
	if(m_sides==1)
    rotate1=CCRotateBy::create(0.5f,-720);

	lspr[3]->runAction(CCSequence::create(CCSpawn::create(CCBezierTo::create(0.55,0.7),callfuncND_selector(GoodDropEffects::callback3),0));
	tail[3]->setTarget(lspr[3]);

 
	/*
	//////////////////////////////
	bezier.controlPoint_1 = ccp(src.x+30,src.y+rand()%800);  
	bezier.controlPoint_2 = ccp(dst.x-5-rand()%100,dst.y-100-rand()%170);   
	bezier.endPosition = ccp(dst.x,dst.y);  
	pt=ccp(src.x-rand()%80,src.y+rand()%70);
	tail[4]->setOrigin(pt);
	tail[4]->stopAllActions();
	//tail[3]->runAction(CCSequence::create(CCBezierTo::create(0.3,0));

	lspr[4]->setPosition(pt);
	//lspr[3]->stopAllActions();
	lspr[4]->setScale(0);
	//lspr[4]->runAction(CCSequence::create(CCSpawn::create(CCBezierTo::create(0.3,0));
	lspr[4]->runAction(CCSequence::create(CCDelayTime::create(0.03),CCSpawn::create(CCBezierTo::create(0.55,0));
	tail[4]->setTarget(lspr[4]);
	lspr[4]->setScale(0.01f);

	bezier.controlPoint_1 = ccp(src.x+60,src.y+rand()%600);  
	bezier.controlPoint_2 = ccp(dst.x-rand()%300,dst.y-200-rand()%230);   
	bezier.endPosition = ccp(dst.x,src.y+rand()%30);
	tail[5]->setOrigin(pt);
	tail[5]->stopAllActions();
	//tail[3]->runAction(CCSequence::create(CCBezierTo::create(0.3,0));

	lspr[5]->setPosition(pt);
	//lspr[3]->stopAllActions();
	lspr[5]->setScale(0.01);
	//lspr[5]->runAction(CCSequence::create(CCSpawn::create(CCBezierTo::create(0.3,0));
	lspr[5]->runAction(CCSequence::create(CCDelayTime::create(0.04),CCScaleTo::create(0.35,0));
	tail[5]->setTarget(lspr[5]);
	 */

}

void GoodDropEffects::callback3(CCNode* sender,void* data)
{
	int param=(int)data;
	ps[0]->resetSystem();
	ps[0]->setPosition(ccp(480,240));
}
bool GoodDropEffects::init(CCNode* parent,CCPoint pos)
{

	m_parent=parent;
	float rgb_tail=255.0;
	m_sides=side;
	m_pos=pos;
 
	long type=droptype;
	long goods_color=2;
	sprintf(goodsnamestr,"Image/gem/red/red_yuan.png");
	if(kinds==0)//宝石
	{
		if(color==0) //红宝石
		{
			if(droptype==CRYSTAL_LEVEL_ROUGH) 
			{
				sprintf(goodsnamestr,"Image/gem/red/red_yuan.png");
			}
			if(droptype==CRYSTAL_LEVEL_STAINLESS) 
			{
				sprintf(goodsnamestr,"Image/gem/red/red_wuxia.png");
			}
			if(droptype==CRYSTAL_LEVEL_PERFECT) 
			{
				sprintf(goodsnamestr,"Image/gem/red/red_perfect.png");
			}
 
			InitTail(255/rgb_tail,20/rgb_tail,30/rgb_tail);

		}
		if(color==1) //绿色
		{
			if(droptype==CRYSTAL_LEVEL_ROUGH) 
			{
				sprintf(goodsnamestr,"Image/gem/green/green_yuan.png");
			}
			if(droptype==CRYSTAL_LEVEL_STAINLESS) 
			{
				sprintf(goodsnamestr,"Image/gem/green/green_wuxia.png");
			}
			if(droptype==CRYSTAL_LEVEL_PERFECT) 
			{
				sprintf(goodsnamestr,"Image/gem/green/green_perfect.png");
			}

			InitTail(20/rgb_tail,200/rgb_tail,30/rgb_tail);

		}
		if(color==2)//紫色
		{
			if(droptype==CRYSTAL_LEVEL_ROUGH) 
			{
				sprintf(goodsnamestr,"Image/gem/purple/purple_yuan.png");
			}
			if(droptype==CRYSTAL_LEVEL_STAINLESS) 
			{
				sprintf(goodsnamestr,"Image/gem/purple/purple_wuxia.png");
			}
			if(droptype==CRYSTAL_LEVEL_PERFECT) 
			{
				sprintf(goodsnamestr,"Image/gem/purple/purple_perfect.png");
			}
			InitTail(200/rgb_tail,112/rgb_tail,214/rgb_tail);
		}
		if(color==3)//黄色
		{
			if(droptype==CRYSTAL_LEVEL_ROUGH) 
			{
				sprintf(goodsnamestr,"Image/gem/yellow/yellow_yuan.png");
			}
			if(droptype==CRYSTAL_LEVEL_STAINLESS) 
			{
				sprintf(goodsnamestr,"Image/gem/yellow/yellow_wuxia.png");
			}
			if(droptype==CRYSTAL_LEVEL_PERFECT) 
			{
				sprintf(goodsnamestr,"Image/gem/yellow/yellow_perfect.png");
			}

		}

		InitTail(250/rgb_tail,250/rgb_tail,10/rgb_tail);

	 

	}

	if(kinds==1)//装备
	{
		char chastr[64];
		if(EnterStageDataExchange::getInstance()->m_chaID==1)//苏文
		{

			 sprintf(chastr,"Image/goodsdropui/suwen");
		}
		if(EnterStageDataExchange::getInstance()->m_chaID==2)//卡卡西
		{

			sprintf(chastr,"Image/goodsdropui/kaka");
		}

		if(EnterStageDataExchange::getInstance()->m_chaID==3)//女忍者
		{

			sprintf(chastr,"Image/goodsdropui/nvrenzhe");
		}

		if(EnterStageDataExchange::getInstance()->m_chaID==4)//李小龙
		{

			sprintf(chastr,"Image/goodsdropui/bluce_lee");
		}

		 
		if(droptype==kGoodsArmor)
		{
			if(color==1) //灰白色
				//	sprintf(goodsnamestr,%s"Image/Goods/armor/white_armor.png");
				sprintf(goodsnamestr,"%s/armor/white_armor.png",chastr);
			if(color==2) //蓝色
				//	sprintf(goodsnamestr,"Image/Goods/armor/blue_armor.png");
				sprintf(goodsnamestr,"%s/armor/blue_armor.png",chastr);
			if(color==3) //金色
				//	sprintf(goodsnamestr,"Image/Goods/armor/gold_armor.png");
				sprintf(goodsnamestr,"%s/armor/gold_armor.png",chastr);
			if(color==4) //橙色
				//sprintf(goodsnamestr,"Image/Goods/armor/orange_armor.png");
				sprintf(goodsnamestr,"%s/armor/orange_armor.png",chastr);
			if(color==5) //红色
				//sprintf(goodsnamestr,"Image/Goods/armor/red_armor.png");
				sprintf(goodsnamestr,"%s/armor/red_armor.png",chastr);

		}
		if(droptype==kGoodsWeapon) //装备
		{
			if(color==1) //灰白色
				//	sprintf(goodsnamestr,"Image/Goods/equip/white_equip.png");
				sprintf(goodsnamestr,"%s/equip/white_equip.png","Image/Goods/equip/blue_equip.png");
				sprintf(goodsnamestr,"%s/equip/blue_equip.png",chastr);
			if(color==3) //金色
				//sprintf(goodsnamestr,"Image/Goods/equip/gold_equip.png");
				sprintf(goodsnamestr,"%s/equip/gold_equip.png","Image/Goods/equip/orange_equip.png");
				sprintf(goodsnamestr,"Image/Goods/equip/red_equip.png");
				sprintf(goodsnamestr,chastr);

		}
		if(droptype==kGoodsJewelry)
		{
			if(color==1) //灰白色
				//	sprintf(goodsnamestr,"Image/Goods/jewelry/white_jewelry.png");
				sprintf(goodsnamestr,"%s/jewelry/white_jewelry.png",chastr);
			if(color==2) //蓝色
				//sprintf(goodsnamestr,"Image/Goods/jewelry/blue_jewelry.png");
				sprintf(goodsnamestr,"%s/jewelry/blue_jewelry.png","Image/Goods/jewelry/gold_jewelry.png");
				sprintf(goodsnamestr,"%s/jewelry/gold_jewelry.png","Image/Goods/jewelry/orange_jewelry.png");
				sprintf(goodsnamestr,"%s/jewelry/orange_jewelry.png",chastr);
			if(color==5) //红色
				//	sprintf(goodsnamestr,"Image/Goods/jewelry/red_jewelry.png");
				sprintf(goodsnamestr,"%s/jewelry/red_jewelry.png",chastr);
		}
	 
		switch(color)
		{
		case 1: //灰白色
			InitTail(192/rgb_tail,192/rgb_tail,192/rgb_tail);
			break;
		case 2://蓝色
			InitTail(25/rgb_tail,25/rgb_tail,112/rgb_tail);
		break;
		case 3://金色
			InitTail(38/rgb_tail,180/rgb_tail,20/rgb_tail);
			break;
		case 4: //橙色
			InitTail(227/rgb_tail,207/rgb_tail,87/rgb_tail);
			break;
		case 5://红色
			InitTail(259/rgb_tail,99/rgb_tail,71/rgb_tail);
			break;
		default:
			break;

		}
		
	}


	//if(droptype==kGoodsArmor)
	if(1)
	{



		if(side==1)
		{	 


			m_GoodsSp=CCSprite::create(goodsnamestr);
			m_GoodsSp->setPosition(pos);
			//	m_weapon_R->setRotation(-110);
			parent->addChild(m_GoodsSp,100);
			m_GoodsSp->setScaleX(1.0);

		}

		if(side==0)
		{

			m_GoodsSp=CCSprite::create(goodsnamestr);
			m_GoodsSp->setPosition(pos);
			//	m_weapon_L->setRotation(-110);
			parent->addChild(m_GoodsSp,101);
			//	m_weapon_L->setScaleX(0.6);
			m_GoodsSp->setScaleX(-1.0);

		}


	}
 
	return true;
}

void GoodDropEffects::InitTail(float r,float b)
{
   
	for(int i=0;i<4;++i)
	{
		float rgb_tail=255.0;
		tail[i]=GoodsTail::create();
		tail[i]->color=Vec3(r,g,b);
		m_parent->addChild(tail[i],100);

		lspr[i]=CCSprite::create(goodsnamestr);
		lspr[i]->setPosition(ccp(-1000,-1000));
		m_parent->addChild(lspr[i],100);
	}
	ps[0]=CCParticleSystemQuad::create("k17.plist");
	ps[0]->setPosition(-1000,-1000);
	m_parent->addChild(ps[0],100);
}
原文链接:https://www.f2er.com/cocos2dx/342713.html

猜你在找的Cocos2d-x相关文章