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);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


    本文实践自 RayWenderlich、Ali Hafizji 的文章《How To Create Dynamic Textures with CCRenderTexture in Cocos2D 2.X》,文中使用Cocos2D,我在这里使用Cocos2D-x 2.1.4进行学习和移植。在这篇文章,将会学习到如何创建实时纹理、如何用Gimp创建无缝拼接纹
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@163.com微信公众号:HopToad 欢迎转载,转载标注出处:http://blog.csdn.netotbaron/article/details/424343991.  软件准备 下载地址:http://cn.cocos2d-x.org/download 2.  简介2.1         引用C
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从Cocos2D-x官网上下载,进入网页http://www.cocos2d-x.org/download,点击Cocos2d-x以下的Download  v3.0,保存到自定义的文件夹2:从python官网上下载。进入网页https://www.python.org/downloads/,我当前下载的是3.4.0(当前最新
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发引擎,易学易用,支持多种智能移动平台。官网地址:http://cocos2d-x.org/当前版本:2.0    有很多的学习资料,在这里我只做为自己的笔记记录下来,错误之处还请指出。在VisualStudio2008平台的编译:1.下载当前稳
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《最强大脑》娱乐节目。将2048改造成一款挑战玩家对数字记忆的小游戏。邮箱:appdevzw@163.com微信公众号:HopToadAPK下载地址:http://download.csdn.net/detailotbaron/8446223源码下载地址:http://download.csdn.net/
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试以QtCreatorIDE来进行CMake构建。Cocos2d-x3.X地址:https://github.com/cocos2d/cocos2d-x1.打开QtCreator,菜单栏→"打开文件或项目...",打开cocos2d-x目录下的CMakeLists.txt文件;2.弹出CMake向导,如下图所示:设置
 下载地址:链接:https://pan.baidu.com/s/1IkQsMU6NoERAAQLcCUMcXQ提取码:p1pb下载完成后,解压进入build目录使用vs2013打开工程设置平台工具集,打开设置界面设置: 点击开始编译等待编译结束编译成功在build文件下会出现一个新文件夹Debug.win32,里面就是编译
分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net前言上次用象棋演示了cocos2dx的基本用法,但是对cocos2dx并没有作深入的讨论,这次以超级马里奥的源代码为线索,我们一起来学习超级马里奥的实
1. 圆形音量button事实上作者的本意应该是叫做“电位计button”。可是我觉得它和我们的圆形音量button非常像,所以就这么叫它吧~先看效果:好了,不多解释,本篇到此为止。(旁白: 噗。就这样结束了?)啊才怪~我们来看看代码:[cpp] viewplaincopyprint?CCContro
原文链接:http://www.cnblogs.com/physwf/archive/2013/04/26/3043912.html为了进一步深入学习贯彻Cocos2d,我们将自己写一个场景类,但我们不会走的太远,凡是都要循序渐进,哪怕只前进一点点,那也至少是前进了,总比贪多嚼不烂一头雾水的好。在上一节中我们建
2019独角兽企业重金招聘Python工程师标准>>>cocos2d2.0之后加入了一种九宫格的实现,主要作用是用来拉伸图片,这样的好处在于保留图片四个角不变形的同时,对图片中间部分进行拉伸,来满足一些控件的自适应(PS: 比如包括按钮,对话框,最直观的形象就是ios里的短信气泡了),这就要求图
原文链接:http://www.cnblogs.com/linji/p/3599478.html1.环境和工具准备Win7VS2010/2012,至于2008v2版本之后似乎就不支持了。 2.安装pythonv.2.0版本之前是用vs模板创建工程的,到vs2.2之后就改用python创建了。到python官网下载版本2.7.5的,然后
环境:ubuntu14.04adt-bundle-linux-x86_64android-ndk-r9d-linux-x86_64cocos2d-x-3.0正式版apache-ant1.9.3python2.7(ubuntu自带)加入环境变量exportANDROID_SDK_ROOT=/home/yangming/adt-bundle-linux/sdkexportPATH=${PATH}:/$ANDROID_SDK_ROOTools/export
1开发背景游戏程序设计涉及了学科中的各个方面,鉴于目的在于学习与进步,本游戏《FlappyBird》采用了两个不同的开发方式来开发本款游戏,一类直接采用win32底层API来实现,另一类采用当前火热的cocos2d-x游戏引擎来开发本游戏。2需求分析2.1数据分析本项目要开发的是一款游
原文链接:http://www.cnblogs.com/linji/p/3599912.html//纯色色块控件(锚点默认左下角)CCLayerColor*ccc=CCLayerColor::create(ccc4(255,0,0,128),200,100);//渐变色块控件CCLayerGradient*ccc=CCLayerGradient::create(ccc4(255,0,0,
原文链接:http://www.cnblogs.com/linji/p/3599488.html//载入一张图片CCSprite*leftDoor=CCSprite::create("loading/door.png");leftDoor->setAnchorPoint(ccp(1,0.5));//设置锚点为右边中心点leftDoor->setPosition(ccp(240,160));/
为了答谢广大学员对智捷课堂以及关老师的支持,现购买51CTO学院关老师的Cocos2d-x课程之一可以送智捷课堂编写图书一本(专题可以送3本)。一、Cocos2d-x课程列表:1、Cocos2d-x入门与提高视频教程__Part22、Cocos2d-x数据持久化与网络通信__Part33、Cocos2d-x架构设计与性能优化内存优
Spawn让多个action同时执行。Spawn有多种不同的create方法,最终都调用了createWithTwoActions(FiniteTimeAction*action1,FiniteTimeAction*action2)方法。createWithTwoActions调用initWithTwoActions方法:对两个action变量初始化:_one=action1;_two=action2;如果两个a
需要环境:php,luajit.昨天在cygwin上安装php和luajit环境,这真特么是一个坑。建议不要用虚拟环境安装打包环境,否则可能会出现各种莫名问题。折腾了一下午,最终将环境转向linux。其中,luajit的安装脚本已经在quick-cocos2d-x-develop/bin/中,直接luajit_install.sh即可。我的lin
v3.0相对v2.2来说,最引人注意的。应该是对触摸层级的优化。和lambda回调函数的引入(嗯嗯,不枉我改了那么多类名。话说,每次cocos2dx大更新。总要改掉一堆类名函数名)。这些特性应该有不少人研究了,所以今天说点跟图片有关的东西。v3.0在载入图片方面也有了非常大改变,仅仅只是