cocos2dx 常用的基本功能


<strong><span style="font-size:24px;color:#009900;">使用plist文件添加动画</span></strong>
//【addAction】
		CCAnimation* animation = HelloWorld::BuilderAnimation("Boss1.plist","Boss1_attack_%02d.png",1,5);
		animation->setLoops(-1);
		CCAnimate* boss = CCAnimate::create(animation);
		CCFiniteTimeAction *seq = CCSequence::create(boss, NULL);

		CCSprite* sprite = CCSprite::create();
		sprite->runAction(seq);
		sprite->setScale(2);
		sprite->setPosition(ccp(300,200));
		addChild(sprite,1);

//【BuilderAnimation】
CCAnimation* HelloWorld::BuilderAnimation(const char* plistName,const char* frameName,int startFrame ,int endFrame)
{
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistName);

	CCArray* animFrames = CCArray::createWithCapacity(endFrame+1);
	char str[100] = {0};
	for(int i = startFrame; i < endFrame; i++)
	{
		sprintf(str, frameName, i);
		CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
		animFrames->addObject(frame);
	}
	CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3f);
	//animation->setLoops(-1);
	return animation;
}



<strong><span style="font-size:24px;color:#009900;">//【精灵的 4 种生成方式】</span></strong>
//【方法一】图片生成
CCSprite* spr1 = CCSprite::create("Icon.png");
spr1->setPosition(ccp(70,150));
addChild(spr1);
//【方法二】图片 + 区域
CCSprite* spr2 = CCSprite::create("Icon.png",CCRectMake(0,0,30,30));;
	spr2->setPosition(ccp(150,150));
	addChild(spr2);
//【方法三】通过帧缓存中的一帧名字生成
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("test_icon.plist");
	CCSprite* spr3 = CCSprite::createWithSpriteFrameName("Icon.png");
	spr3->setPosition(ccp(230,150));
	addChild(spr3);
//【方法四】通过另外一帧生成一个图片
	CCSpriteFrame* frame = CCSpriteFrame::create("Icon.png",CCRectMake(0,0,40,30));
	CCSprite* spr4 = CCSprite::createWithSpriteFrame(frame);
	spr4->setPosition(ccp(310,150));
	addChild(spr4);

<span style="font-size:18px;">//【精灵的基本操作】</span>
 //设置半透明
    sprite->setOpacity(127);
    //设置混合色
    sprite->setColor(ccc3(255, 255, 0));
    //设置贴图尺寸大小
    sprite->setTextureRect(CCRectMake(0, 0, 35, 35));
//设置不可见
    sprite->setVisible(false);
//设置精灵的锚点
sprite->setAnchorPoint(ccp(0,0));
		ccp(0,0) : 左下    ccp(0.5,0.5) : 中心    ccp(1,1) : 右上   

<span style="font-size:18px;"><strong>//【两种常用层Layer】</strong></span>
	//【默认黑色】
	CCLayer* layer = CCLayer::create();
	addChild(layer);

	//【黄色】
	CCLayerColor* layerColor = CCLayerColor::create(ccc4(255,255,0,255));
	addChild(layerColor);
	layerColor->setContentSize(CCSizeMake(250,250));

	//【蓝色】
	CCLayerColor* layerColor2 = CCLayerColor::create(ccc4(0,0,255,255),150,150);
	addChild(layerColor2);




<strong><span style="font-size:18px;">//【Tag的作用与使用】</span></strong>
		CCSprite* sp = CCSprite::create("Icon.png");
		sp->setPosition(ccp(100,200));
		addChild(sp);

		CCSprite* sp1 = CCSprite::create("Icon.png");
		sp1->setPosition(ccp(200,200));
		addChild(sp1,0,832);
		this->testSprite();
void HelloWorld::testSprite()
{
	CCSprite* sp = (CCSprite*)this->getChildByTag(832);
	sp->setScale(2);
}

<strong><span style="font-size:18px;">//【layer 默认充满屏幕】</span></strong>
		CCLayerColor* layer = CCLayerColor::create(ccc4(255, 0, 0, 255));
		addChild(layer);
		CCLOG("%f,%f",layer->getAnchorPoint().x,layer->getAnchorPoint().y);
		CCLOG("%f,%f",layer->getPositionX(),layer->getPositionY());
		CCLOG("%f,%f",layer->getContentSize().width,layer->getContentSize().height);



<strong><span style="font-size:24px;color:#009900;">FontTest
</span></strong>
//【CCLabelTTF】
	CCLabelTTF* pLabel1 = CCLabelTTF::create("CCLabelTTF-Thonburi", "Thonburi", 24);
		pLabel1->setPosition(ccp(170,280));
		addChild(pLabel1);

		CCLabelTTF* pLabe2 = CCLabelTTF::create();
		pLabe2->setFontSize(20);
		pLabe2->setString("CCLabelTTF-Helvetica");
		pLabe2->setPosition(ccp(170,250));
		addChild(pLabe2);
		
//【CCLabelAtlas】
CCLabelAtlas* label = CCLabelAtlas::create("Atlas-823", "testfont.png", 48, 64, ' '); //???参数
		label->setPosition(ccp(0,190));
		addChild(label);
		label->setColor(ccc3(255,0,0));

		CCLabelAtlas* label2 = CCLabelAtlas::create("LabelAtlas", "testfont.plist");
		label2->setPosition(ccp(0,140));
		addChild(label2);

//【CCLabelBMFont】
		CCLabelBMFont* labelBM = CCLabelBMFont::create("Himi", "testChinese.fnt");
		labelBM->setPosition(ccp(180,100));
		addChild(labelBM);



<strong><span style="font-size:24px;color:#009900;">InputTest</span></strong>
:public cocos2d::public CCTextFieldDelegate
//重写CCTextFieldDelegate的回调函数
	//当用户启动虚拟键盘时的回调函数
	virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);
	//当用户关闭虚拟键盘时的回调函数
	virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);
	//当用户进行输入时的回调函数
	virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);
	//当用户删除文字时的回调函数
	virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen);

bool HelloWorld::onTextFieldAttachWithIME(CCTextFieldTTF * pSender){
	CCLOG("onTextFieldAttachWithIME");
	return false;
	//return true;  //不启动
}
bool HelloWorld::onTextFieldDetachWithIME(CCTextFieldTTF * pSender){
	CCLOG("onTextFieldDetachWithIME");
	return false;
	//return true:不关闭
}
bool HelloWorld::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen){
	CCLOG("onTextFieldInsertText...");
	return false;
	//return true:不会输入进字符
}
bool HelloWorld::onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen){
	CCLOG("onTextFieldDeleteBackward");
	return false;
	//return true:不删除
}



<HelloWorld init>
CCSize size = CCDirector::sharedDirector()->getWinSize();

		CCTextFieldTTF* textField = CCTextFieldTTF::textFieldWithPlaceHolder("Click input...", "Helvetica", 24);
		textField->setPosition(ccp(size.width*0.5,size.height*0.7));
		addChild(textField);

		//绑定接口
		textField->setDelegate(this);
		//开启输入
		textField->attachWithIME();
		//关闭输入
		textField->detachWithIME();



<strong><span style="font-size:24px;color:#009900;">MenuTest</span></strong>

//----CCMenuItemFont
	CCMenuItemFont*  itemFont = CCMenuItemFont::create("Start Game", this,menu_selector(HelloWorld::menuFun));
	itemFont->setPosition(ccp(-120,80));

//----CCMenuItemImage
	CCMenuItemImage* imageItem = CCMenuItemImage::create("CloseNormal.png","CLoseSelected.png", this,menu_selector(HelloWorld::menuFun));
	imageItem->setPosition(ccp(-20,80));

//----CCMenuItemLabel
	CCLabelTTF * lableTTF = CCLabelTTF::create("Back Main Menu", "Helvetica", 20); 
	CCMenuItemLabel * labelItem =CCMenuItemLabel::create(lableTTF,this,menu_selector(HelloWorld::menuFun));
	labelItem->setPosition(ccp(80,80));

//----CCMenuItemSprite
	CCSprite* spNor = CCSprite::create("Icon.png");
	spNor->setColor(ccc3(255, 255, 0 ));
	CCSprite* spSelected =CCSprite::create("Icon.png");
	CCMenuItemSprite* spriteItem = CCMenuItemSprite::create(spNor,spSelected, this,menu_selector(HelloWorld::menuFun));
	spriteItem->setPosition(ccp(-80,-20));


//----CCMenuItemToggle
	CCMenuItemFont * fontItem1 = CCMenuItemFont::create("Music ON");
	CCMenuItemFont * fontItem2 = CCMenuItemFont::create("Music OFF");
	CCMenuItemToggle* toggleItem = CCMenuItemToggle::createWithTarget(this,menu_selector(HelloWorld::menuFun), fontItem1,fontItem2,NULL);
	toggleItem->setPosition(ccp(20,-20));

CCMenu* menu = CCMenu::create(itemFont,imageItem,labelItem,spriteItem,toggleItem,NULL);
	addChild(menu);


void HelloWorld::menuFun(CCObject* sender){ }



<strong><span style="font-size:24px;color:#009900;">CCMenu菜单</span></strong>
//----CCMenuItemFont
	CCMenuItemFont*  itemFont = CCMenuItemFont::create("Start Game", this,menu_selector(HelloWorld::menuFun));
	itemFont->setPosition(ccp(-120,80));

//----CCMenuItemImage
	CCMenuItemImage* imageItem = CCMenuItemImage::create("CloseNormal.png","CLoseSelected.png", 
this,menu_selector(HelloWorld::menuFun));
	imageItem->setPosition(ccp(-20,80));

//----CCMenuItemLabel
	CCLabelTTF * lableTTF = CCLabelTTF::create("Back Main Menu", "Helvetica", 20); 
	CCMenuItemLabel * labelItem =CCMenuItemLabel::create(lableTTF,this,menu_selector(HelloWorld::menuFun));
	labelItem->setPosition(ccp(80,80));

//----CCMenuItemSprite
	CCSprite* spNor = CCSprite::create("Icon.png");
	spNor->setColor(ccc3(255, 255, 0 ));
	CCSprite* spSelected =CCSprite::create("Icon.png");
	CCMenuItemSprite* spriteItem = CCMenuItemSprite::create(spNor,spSelected, this,menu_selector(HelloWorld::menuFun));
	spriteItem->setPosition(ccp(-80,-20));


//----CCMenuItemToggle
	CCMenuItemFont * fontItem1 = CCMenuItemFont::create("Music ON");
	CCMenuItemFont * fontItem2 = CCMenuItemFont::create("Music OFF");
	CCMenuItemToggle* toggleItem = CCMenuItemToggle::createWithTarget(this,menu_selector(HelloWorld::menuFun), fontItem1,fontItem2,NULL);
	toggleItem->setPosition(ccp(20,-20));


	CCMenu* menu = CCMenu::create(itemFont,imageItem,labelItem,spriteItem,toggleItem,NULL);
	addChild(menu);



<strong><span style="font-size:24px;color:#009900;">CCControlSwitch 开关</span></strong>
#include "cocos-ext.h"
using namespace cocos2d;
using namespace CocosDenshion;
USING_NS_CC;          // using namespace cocos2d
USING_NS_CC_EXT;     // using namespace cocos2d::extension



CCControlSwitch *pSwitch= CCControlSwitch::create(
			CCSprite::create("switch-mask.png"),
			CCSprite::create("switch-on.png"),
			CCSprite::create("switch-off.png"),
			CCSprite::create("switch-thumb.png"),
			CCLabelTTF::create("ON", "Arial-BoldMT", 16),
			CCLabelTTF::create("OFF", "Arial-BoldMT", 16)
			);
		pSwitch->setPosition(ccp(200,200));
		//设置关闭状态
		pSwitch->setOn(false);
		//设置可操作
		pSwitch->setEnabled(true);
		//获取是否为打开(on)
		CCLOG("是否打开状态:%i",pSwitch->isOn());
		//获取当前开关状态是否为手动拖动开关进行的
		CCLOG("是否手动拖动的开关:%i",pSwitch->hasMoved());
		addChild(pSwitch);
        


<strong><span style="font-size:24px;color:#009900;">CCControlSlider滑动条</span></strong>
#include "cocos-ext.h"
using namespace extension;

void valueChanged(CCObject *sender, CCControlEvent controlEvent);

void HelloWorld::valueChanged(CCObject *sender, CCControlEvent controlEvent)
{
	CCControlSlider*slider= (CCControlSlider*)this->getChildByTag(921);
	CCLabelTTF * ttf = (CCLabelTTF*)this->getChildByTag(922);
	ttf->setString(CCString::createWithFormat("silder current value = %.02f", slider->getValue())->getCString());
}



Init
CCControlSlider*slider=CCControlSlider::create("sliderBg.png","sliderProgre											ss.png","sliderThumb.png");
	slider->setPosition(ccp(200,170));
	//设置滑动条最大值
	slider->setMaximumValue(100);
	//设置滑动条最小值
	slider->setMinimumValue(0);
	addChild(slider,0,921);
	//设置监听,当滑动条的值发生变化后,会响应valueChanged函数
	//CCControlEventValueChanged 值改变
	slider->addTargetWithActionForControlEvent(this, 			 			cccontrol_selector(HelloWorld::valueChanged), 	CCControlEventValueChanged);

	//用于展示当前滑动条的滑动值
	CCLabelTTF * ttf = CCLabelTTF::create("", "Helvetica", 20);
	ttf->setPosition(ccp(200,210));
	ttf->setString(CCString::createWithFormat("slider current value = %.02f", 										slider->getValue())->getCString());
	addChild(ttf,0,922);



<strong><span style="font-size:24px;color:#009900;">ButtonTest</span></strong>
#include "cocos2d.h"
#include "Box2D/Box2D.h"
#include "SimpleAudioEngine.h"

#include "cocos-ext.h"
using namespace extension;


#include "HelloWorldScene.h"

using namespace cocos2d;
using namespace CocosDenshion;
        
INIT:
CCLabelTTF *titleButton = CCLabelTTF::create("NO", "Marker Felt", 25);
		CCControlButton * btn  = CCControlButton::create(titleButton,CCScale9Sprite::create("button.png"));
		btn->setPosition(ccp(240,170));

		//按钮被选中后背景图响应的状态
		btn->setBackgroundSpriteForState(CCScale9Sprite::create("buttonHighlighted.png"), CCControlStateHighlighted);
		//按钮被选中后文字颜色响应的状态
		btn->setTitleColorForState(ccc3(255, 0, 0), CCControlStateHighlighted);
		//按钮被选中后文字响应的状态
		btn->setTitleForState(CCString::create("YES"), CCControlStateHighlighted);
		addChild(btn);

		//按钮按下事件回调
		btn->addTargetWithActionForControlEvent(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown);
		//按钮在其内部抬起事件回调
		btn->addTargetWithActionForControlEvent(this, cccontrol_selector(HelloWorld::touchUpInsideAction), CCControlEventTouchUpInside);
		//按钮在其外部抬起事件回调
		btn->addTargetWithActionForControlEvent(this, cccontrol_selector(HelloWorld::touchUpOutsideAction), CCControlEventTouchUpOutside);

		//用于显示按钮状态
		CCLabelTTF *titleButtonState = CCLabelTTF::create("", "Marker Felt", 25);
		addChild(titleButtonState,0,923);
		titleButtonState->setPosition(ccp(240,220));




//按钮按下事件回调
	void touchDownAction(CCObject *sender, CCControlEvent controlEvent);
	//按钮在其内部抬起事件回调
	void touchUpInsideAction(CCObject *sender, CCControlEvent controlEvent);
	//按钮在其外部抬起事件回调
	void touchUpOutsideAction(CCObject *sender, CCControlEvent controlEvent);


void HelloWorld::touchDownAction(CCObject *senderz, CCControlEvent controlEvent)
{
	CCLabelTTF *m_pDisplayValueLabel = (CCLabelTTF*)this->getChildByTag(923);
	m_pDisplayValueLabel->setString(CCString::createWithFormat("Push")->getCString());
}
void HelloWorld::touchUpInsideAction(CCObject *sender, CCControlEvent controlEvent)
{
	CCLabelTTF *m_pDisplayValueLabel = (CCLabelTTF*)this->getChildByTag(923);
	m_pDisplayValueLabel->setString(CCString::createWithFormat("Inner Up")->getCString());
}
void HelloWorld::touchUpOutsideAction(CCObject *sender, CCControlEvent controlEvent){
	CCLabelTTF *m_pDisplayValueLabel = (CCLabelTTF*)this->getChildByTag(923);
	m_pDisplayValueLabel->setString(CCString::createWithFormat("Outer Up")->getCString());
}



<strong><span style="font-size:24px;color:#009900;">DrawTest</span></strong>
 
void HelloWorld::draw()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	//【设置颜色】
	ccDrawColor4B(255,0,0,255);
	//【设置线条的宽度】
	glLineWidth(2);
	//【绘制一条直线】
	ccDrawLine(ccp(10,10),ccp(size.width/2,size.height/2));

	ccDrawColor4B(255,255,0,255);
	//【设置像素尺寸】
	ccPointSize(30.0f);
	//【绘制一个点】
	ccDrawPoint(ccp(size.width/2,size.height/2));
	

	//【绘制一个○】
	ccDrawCircle(ccp(size.width*0.5,size.height*0.5),50,CC_DEGREES_TO_RADIANS(270),30,true);


	//【绘制多边形】
	ccDrawColor4B(0,255,0,255);
	glLineWidth(5);
	CCPoint vertices[] = {ccp(70,150),ccp(150,150),ccp(150,200),ccp(190,300)};
	ccDrawPoly(vertices,4,true);

	//【绘制填充的多边形】
	CCPoint filledVertices[] = {ccp(0,120),ccp(50,120),ccp(50,170),ccp(25,200),ccp(0,170)};
	ccDrawSolidPoly(filledVertices,5,ccc4f(0.5f,0.5f,1,1));

	//【绘制贝塞尔曲线】
	ccDrawQuadBezier(ccp(0,size.height),ccp(size.width*0.5,size.height*0.5),ccp(size.width,size.height),50);

	//【绘制立体的贝塞尔曲线】
	ccDrawCubicBezier(ccp(size.width/2,size.height/2),ccp(size.width/2+30,size.height/2+50),ccp(size.width/2+60,size.height/2-50),ccp(size.width,size.height/2),100);
	
	//【绘制填充矩形】
	ccDrawSolidRect(ccp(240,50),ccp(300,10),ccc4f(255,177,177,255));
}



<strong><span style="font-size:24px;color:#009900;">UpdateTest
</span></strong>
 
Init:
//----------scheduleUpdate
//    CCSprite* sp = CCSprite::create("Icon.png");
//    sp->setPosition(ccp(80,100));
//    addChild(sp,0,922);
//    //更新函数
//    scheduleUpdate();


//----------schedule
CCSprite* sp = CCSprite::create("Icon.png");
sp->setPosition(ccp(80,100));
addChild(sp,0,922);
//自定义更新函数 每一帧都调用
schedule(schedule_selector(HelloWorld::myUpdate));
//自定义更新函数 每秒执行一次
//schedule(schedule_selector(HelloWorld::myUpdate),1.f);


void update(float dt);
void myUpdate(float dt);


void HelloWorld::update( float dt )
{
	//停止更新
	//    unscheduleUpdate();

	CCSprite*sp =(CCSprite*)this->getChildByTag(922);
	if(sp->getPositionX()<260){
		sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,1)));
	}else{
		sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,-1)));
	}
}

void HelloWorld::myUpdate( float dt )
{
	//停止更新
	//unschedule(schedule_selector(HelloWorld::myUpdate));
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	CCSprite*sp =(CCSprite*)this->getChildByTag(922);
	int w = sp->getTextureRect().size.width;
	int h = sp->getTextureRect().size.height;

	CCLOG("[%d,%d]",w,h);

	static int speedX=1 , speedY=1;
	sp->setPosition(ccpAdd(sp->getPosition(), ccp(speedX,speedY)));

	if(sp->getPositionX()<=0+w/2){
		speedX = -speedX;
		speedY = speedY;
	}
	else if(sp->getPositionX()>=size.width-w/2){
		speedX = -speedX;
		speedY = speedY;
	}
	else if(sp->getPositionY()>=size.height-h/2){
		speedX = speedX;
		speedY = -speedY;
	}
	else if(sp->getPositionY()<=0+h/2){
		speedX = speedX;
		speedY = -speedY;
	}
	


	/*if(sp->getPositionX()<260){
		sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,1)));
	}else{
		sp->setPosition(ccpAdd(sp->getPosition(), ccp(1,-1)));
	}*/
}

//unscheduleAllSelectors()停止所有更新函数



<strong><span style="font-size:24px;color:#009900;">ProgressTest
</span></strong>
 
CCProgressTimer * pross = CCProgressTimer::create(CCSprite::create("Icon.png"));
		pross->setPosition(ccp(100,180));
		//设置进度条的样式
		pross->setType( kCCProgressTimerTypeRadial);
		//设置进度值范围[0,100]
		pross->setPercentage(100);
		//反进度计时
		pross->setReverseProgress(true);
		addChild(pross);
		CCProgressTo *to1 = CCProgressTo::create(2, 100);
		pross->runAction( CCRepeatForever::create(to1)); //一直循环


		CCProgressTimer * prossR = CCProgressTimer::create(CCSprite::create("Icon.png"));
		prossR->setPosition(ccp(210,180));
		prossR->setType( kCCProgressTimerTypeBar );
		//设置计时器运动方向
		prossR->setMidpoint(ccp(0,1));
		//设置计时器的宽高起始比例
		prossR->setBarChangeRate(ccp(0, 1));

		addChild(prossR);
		CCProgressTo *to2 = CCProgressTo::create(2, 100);
		prossR->runAction( CCSequence::create(to2,NULL));//循环一次



<strong><span style="font-size:24px;color:#009900;">ScrollViewTest(划屏效果)</span></strong>

  
//当scrollview发生移动时响应
	virtual void scrollViewDidScroll(CCScrollView* view);
	//当scrollview发生缩放时响应
	virtual void scrollViewDidZoom(CCScrollView* view);

void HelloWorld::scrollViewDidScroll(CCScrollView* view){
	CCLOG("ScrollView移动");
}

void HelloWorld::scrollViewDidZoom(CCScrollView* view){

	CCLOG("ScrollView缩放");
}

Init:
CCSize size = CCDirector::sharedDirector()->getWinSize();
		//创建一个layer作为容器
		CCLayer * containLayer = CCLayer::create();

		CCSprite *sp =CCSprite::create("HelloWorld.png");
		sp->setPosition(ccp(size.width*0.5,size.height*0.5));
		CCSprite *sp2 =CCSprite::create("Default.png");
		sp2->setPosition(ccp(sp->getContentSize().width,size.height*0.5));
		//往容器中添加节点
		containLayer->addChild(sp);
		containLayer->addChild(sp2);
		containLayer->setContentSize(CCSizeMake(size.width*3, size.height));

		//创建视图添加当前layer
		CCScrollView * scrollView = CCScrollView::create(CCSizeMake(size.width*2, size.height));
		addChild(scrollView);

		scrollView->isDragging();//用户是否正在CCScrollView中操作
		scrollView->isTouchMoved();//用户是否正在CCScrollView移动操作
		scrollView->isBounceable();//是否开启弹性效果
		scrollView->setBounceable(true);//设置scrollview有弹跳效果(默认为true)
		scrollView->setViewSize(CCSizeMake(size.width*2, size.height));//设置scrollView尺寸
		scrollView->setContainer(containLayer);//设置容器
		scrollView->getViewSize();//获取视图尺寸

		//务必在AppController.mm中开启iOS对多触点的支持
		//[__glView setMultipleTouchEnabled:YES];
		scrollView->setTouchEnabled(true);//开启监听多触点
		//scrollView->setDelegate(this);//注册监听



<strong><span style="font-size:24px;color:#009900;">常用的49种动作</span></strong>
using namespace cocos2d;

void callbackC();
	void callbackN(CCNode* sender);
	void callbackND(CCNode* sender, void* data);


void HelloWorld::callbackC()
{
	CCLOG("callbackC");
}

void HelloWorld::callbackN(CCNode* sender)
{
	CCLOG("callbackN");
}

void HelloWorld::callbackND(CCNode* sender, void* data)
{
	CCLOG("callbackND");
}



Init:

CCSprite* sp = CCSprite::create("Icon.png");
sp->setPosition(ccp(150,150));
addChild(sp,0,922);

//---------CCMoveBy
		    /*CCActionInterval * moveBy = CCMoveBy::create(5, ccp(300,200));
		    CCActionInterval*  actionByBack = moveBy->reverse();
		    sp->runAction(actionByBack);*/

//---------CCScaleTo
		    /*CCActionInterval* scaleTo = CCScaleTo::create(2, 2);
		    sp->runAction(scaleTo);*/

//---------CCScaleBy
		//    CCActionInterval* scaleBy = CCScaleBy::create(2, 2);
		//    CCActionInterval*  actionByBack = scaleBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCRotateTo
		//    CCActionInterval* rotateTo = CCRotateTo::create(2, 90);
		//    sp->runAction(rotateTo);

//---------CCRotateBy
		//    CCActionInterval* rotateBy = CCRotateBy::create(2, 90);
		//    CCActionInterval*  actionByBack = rotateBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCSkewTo
		//    CCActionInterval* skewTo =CCSkewTo::create(2, 10, 10);
		//    sp->runAction(skewTo);

//---------CCSkewBy    
		//    CCActionInterval* skewBy =CCSkewBy::create(2, 10, 10);
		//    CCActionInterval*  actionByBack = skewBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCJumpTo
		//    CCActionInterval* jumpTo =CCJumpTo::create(2, ccp(300,200), 50, 4);
		//    sp->runAction(jumpTo);

//---------CCJumBy
		//    CCActionInterval* jumpBy =CCJumpBy::create(2, ccp(300,200), 50, 4);
		//    CCActionInterval*  actionByBack = jumpBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCBezier 
		//    ccBezierConfig bezierCon;
		//    bezierCon.controlPoint_1 = CCPointMake(200, 150);
		//    bezierCon.controlPoint_2 = CCPointMake(200, 260);
		//    bezierCon.endPosition = CCPointMake(340,100);
		//    
		//    //--CCBezierTo
		//    CCActionInterval* bezierTo =CCBezierTo::create(2, bezierCon);
		//    sp->runAction(bezierTo);
		//    
		//    //--CCBezierBy
		//    CCActionInterval* bezierBy =CCBezierBy::create(2, bezierCon);
		//    CCActionInterval*  actionByBack = bezierBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCFadeIn     
		//    CCActionInterval * fadeIn = CCFadeIn::create(2);
		//    sp->runAction(fadeIn);

//---------CCFadeOut
		//    CCActionInterval * fadeOut = CCFadeOut::create(2);
		//    sp->runAction(fadeOut);

//---------CCTintTo    
		//    CCActionInterval* tintTo =CCTintTo::create(2, 255, 0, 0);
		//    sp->runAction(tintTo);

//---------CCTintBy   
		//    CCActionInterval* tintBy =CCTintBy::create(2, 255, 0, 0);
		//    CCActionInterval* actionByBack = tintBy->reverse();
		//    sp->runAction(actionByBack);

//---------CCBlink
		//    CCActionInterval* blink = CCBlink::create(10, 3);
		//    sp->runAction(blink);


//---------CCDelayTime
		//    CCActionInterval* delayTime = CCDelayTime::create(2);
		//    sp->runAction(delayTime);


//---------CCOrbitCamera
		//    CCActionInterval* orbitCamera = CCOrbitCamera::create(3,1, 0, 45, 180, 90, 0);
		//    sp->runAction(orbitCamera);

//---------CCCardinalSpline
		//    CCPointArray *array = CCPointArray::create(20);
		//    array->addControlPoint(ccp(0, 0));
		//    array->addControlPoint(ccp(210, 0));
		//    array->addControlPoint(ccp(210, 240));
		//    array->addControlPoint(ccp(0, 160));
		//    array->addControlPoint(ccp(0, 0));
		//    
		//    //--CCCardinalSplineTo
		//    CCActionInterval* splineTo = CCCardinalSplineTo::create(4, array, 0);
		//    sp->runAction(splineTo);
		//    
		//    //--CCCardinalSplineBy
		//    CCActionInterval* splineBy = CCCardinalSplineBy::create(4, array, 0);
		//    CCActionInterval* actionByBack =splineBy->reverse();
		//    sp->runAction(actionByBack);


//---------CCCatmullRom 
		    CCPointArray *array = CCPointArray::create(20);
		    array->addControlPoint(ccp(240, 30));
		    array->addControlPoint(ccp(400, 30));
		    array->addControlPoint(ccp(400, 240));
		    array->addControlPoint(ccp(240, 240));
		    array->addControlPoint(ccp(240, 30));
		    
		   //--CCCatmullRomTo
		    /*CCCatmullRomTo * romTo = CCCatmullRomTo::create(2, array);
		    sp->runAction(romTo);*/
		    
		   //--CCCatmullRomTo
		    /*CCActionInterval * romBy = CCCatmullRomBy::create(2, array);
		    CCActionInterval* actionByBack =romBy->reverse();
		    sp->runAction(actionByBack);*/


//---------CCFollow 
		    //创建一个参照物spT
		    /*CCSprite*spT = CCSprite::create("icon.png");
		    spT->setPosition(ccp(420,40));
		    addChild(spT);
		    
		    sp->runAction(CCMoveTo::create(3,ccp(940,sp->getPositionY())));
		    CCFollow* follow = CCFollow::create(sp,CCRectMake(0, 0, 960, 320));
		    this->runAction(follow);*/



//-------CCEaseBounce
		//    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		//    //---CCEaseBounceIn
		//    CCActionInterval* easeBounceIn = CCEaseBounceIn::create(move);
		//    sp->runAction(easeBounceIn);

		//    //---CCEaseBounceIn
		//    CCActionInterval* easeBounceOut = CCEaseBounceOut::create(move);
		//    sp->runAction(easeBounceOut);

//CCEaseBounceInOut
		//    CCActionInterval* easeInOut = CCEaseBounceInOut::create(move);
		//    sp->runAction(easeInOut);

//------CCEaseBack
		    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		    //--CCEaseBackIn
		    CCActionInterval* easeBackIn =  CCEaseBackIn::create(move);
		    sp->runAction(easeBackIn);

		    //--CCEaseBackOut
		    CCActionInterval* easeBackOut =  CCEaseBackOut::create(move);
		    sp->runAction(easeBackOut);

		    //--CCEaseBackInOut
		    CCActionInterval* easeBackInOut =  CCEaseBackInOut::create(move);
		    sp->runAction(easeBackInOut);

//------easeElastic
		//    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		//    //--easeElasticIn
		//    CCActionInterval * easeElasticIn = CCEaseElasticIn::create(move);
		//    sp->runAction(easeElasticIn);

		//    //--CCEaseElasticOut
		//    CCActionInterval * easeElasticOut = CCEaseElasticOut::create(move);
		//    sp->runAction(easeElasticOut);

		//    //--CCEaseElasticInOut
		//    CCActionInterval * easeElasticInOut = CCEaseElasticInOut::create(move);
		//    sp->runAction(easeElasticInOut);


//-------CCEaseExponential
		//    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		//    //--CCEaseExponentialIn
		//    CCActionInterval * exponentinalIn = CCEaseExponentialIn::create(move);
		//    sp->runAction(exponentinalIn);

		//    //--CCEaseExponentialOut
		//    CCActionInterval * exponentinalOut = CCEaseExponentialOut::create(move);
		//    sp->runAction(exponentinalOut);

		//    //--CCEaseExponentialInOut
		//    CCActionInterval * exponentinalInOut = CCEaseExponentialInOut::create(move);
		//    sp->runAction(exponentinalInOut);

//--------CCEaseRateAction
		//    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		//    CCActionInterval* easeRateAction = CCEaseRateAction::create(move,0.5);
		//    sp->runAction(easeRateAction);


//--------CCEaseSine
		//    CCActionInterval* move = CCMoveTo::create(2, ccp(300,sp->getPositionY()));
		//    //--CCEaseSineIn
		//    CCActionInterval *easeSineIn = CCEaseSineIn::create(move);
		//    sp->runAction(easeSineIn);

		//    //--CCEaseSineOut
		//    CCActionInterval *easeSineOut = CCEaseSineOut::create(move);
		//    sp->runAction(easeSineOut);

		//    //--CCEaseSineInOut
		//    CCActionInterval *easeSineInOut = CCEaseSineInOut::create(move);
		//    sp->runAction(easeSineInOut);


//-------CCSpeed
		//    CCActionInterval* move = CCMoveTo::create(10, ccp(300,sp->getPositionY()));
		//    CCSpeed * speed= CCSpeed::create(move, 10);
		//    sp->runAction(speed);


//-------CCSpawn
		//    CCActionInterval* move = CCMoveTo::create(5, ccp(300,sp->getPositionY()));
		//    CCActionInterval* scale = CCScaleTo::create(2, 3);
		//    CCActionInterval* rotate = CCRotateTo::create(4, 190);
		//    CCFiniteTimeAction *spwn = CCSpawn::create(move,scale,rotate,NULL);
		//    sp->runAction(spwn);

//-------CCSequence
		    /*CCActionInterval* move = CCMoveTo::create(2, ccp(300,sp->getPositionY()));
		    CCActionInterval* scale = CCScaleTo::create(2, 3);
		    CCFiniteTimeAction * seq = CCSequence::create(move,scale,NULL);
		    sp->runAction(seq);*/

//-------Reverse CCSequence
		   /* CCActionInterval* move = CCMoveBy::create(2, ccp(300,sp->getPositionY()));
		    CCActionInterval* scale = CCScaleBy::create(2, 3);
		    CCFiniteTimeAction * seq = CCSequence::create(move,scale,NULL);
		    CCFiniteTimeAction * reverseSeq = CCSequence::create(seq,seq->reverse(),NULL);
		    sp->runAction(reverseSeq);*/

//-------CCRepeat
		   /* CCActionInterval* move = CCMoveTo::create(2, ccp(300,sp->getPositionY()));
		    CCActionInterval* move2 =CCMoveTo::create(2,ccp(100,100));
		    CCFiniteTimeAction *seq =CCSequence::create(move,move2,NULL);
		    CCActionInterval* repeat =CCRepeat::create(seq, 2);
		    sp->runAction(repeat);*/

//-------CCRepeatForever
		    /*CCActionInterval* move = CCMoveTo::create(1, ccp(300,sp->getPositionY()));
		    CCActionInterval* move2 =CCMoveTo::create(1,ccp(100,100));
		    CCFiniteTimeAction *seq =CCSequence::create(move,move2,NULL);
		    CCActionInterval* repeatForever =CCRepeatForever::create((CCActionInterval*)seq);
		    sp->runAction(repeatForever);*/


//-------CCCallFunc
		   /* CCActionInterval* move = CCMoveTo::create(1, ccp(300,sp->getPositionY()));
		    CCCallFunc * funCall =CCCallFunc::create(this, callfunc_selector(HelloWorld::callbackC));
		    CCFiniteTimeAction *seq =CCSequence::create(move,funCall,NULL);
		    sp->runAction(seq);*/

//-------CCCallFuncN
		//    CCActionInterval* move = CCMoveTo::create(1, ccp(300,sp->getPositionY()));
		//    CCCallFuncN * funCall =CCCallFuncN::create(this, callfuncN_selector(HelloWorld::callbackN));
		//    CCFiniteTimeAction *seq =CCSequence::create(move,funCall,NULL);
		//    sp->runAction(seq);
		//
//-------CCCallFuncND
		/*CCActionInterval* move = CCMoveTo::create(1, ccp(300,sp->getPositionY()));
		CCCallFuncND * funCall =CCCallFuncND::create(this, callfuncND_selector(HelloWorld::callbackND), (void*)0xbebabeba);
		CCFiniteTimeAction *seq =CCSequence::create(move,funCall,NULL);
		sp->runAction(seq);*/



<strong><span style="font-size:24px;color:#009900;">动画</span></strong>

//定义一个变量用以标识当前显示的帧下标
	int currentFrameIndex;
	//自定义的更新函数
	void myUpdate(float dt);

void HelloWorld::myUpdate(float dt){
	currentFrameIndex++;
	//获取当前所有精灵
	CCArray* array = this->getChildren();
	//防止下标超过最大tag的精灵
	if(currentFrameIndex>=array->count()){
		currentFrameIndex=0;
	}
	//隐藏所有的精灵
	for (int i = 0; i<array->count(); i++) {
		//根据tag索引每一帧并设置不可见
		CCSprite* spT = (CCSprite*)this->getChildByTag(i);
		spT->setVisible(false);
	}
	//让下一帧显示出来
	CCSprite* sp = (CCSprite*)array->objectAtIndex(currentFrameIndex);
	sp->setVisible(true);
}



Init:
//----------------模拟动画实现

		//    //添加个精灵,每个精灵用来表示一帧
		//    CCSprite* frame = CCSprite::create("crop1.png");
		//    CCSprite* frame2 = CCSprite::create("crop2.png");
		//    CCSprite* frame3 = CCSprite::create("crop3.png");
		//    CCSprite* frame4 = CCSprite::create("crop4.png");
		//    
		//    //--另外一种方式:
		//    //    CCSprite* frame = CCSprite::create("crop.png",CCRectMake(0, 0, 100, 86));
		//    //    CCSprite* frame2 = CCSprite::create("crop.png",CCRectMake(100, 0, 100, 86));
		//    //    CCSprite* frame3 = CCSprite::create("crop.png",CCRectMake(200, 0, 100, 86));
		//    //    CCSprite* frame4 = CCSprite::create("crop.png",CCRectMake(300, 0, 100, 86));
		//
		//
		//    //设置一样的坐标
		//    frame ->setPosition(ccp(100,180));
		//    frame2 ->setPosition(ccp(100,180));
		//    frame3 ->setPosition(ccp(100,180));
		//    frame4 ->setPosition(ccp(100,180));
		//    
		//    //设置-4帧不可见,初始化时只显示第一帧
		//    frame2->setVisible(false);
		//    frame3->setVisible(false);
		//    frame4->setVisible(false);
		//    
		//    //添加当前Lyaer中,tag按照顺序~
		//    addChild(frame,0,0);
		//    addChild(frame2,0,1);
		//    addChild(frame3,0,2);
		//    addChild(frame4,0,3);
		//    
		//    //每.5秒调用一次myUpdate(每.5切换一帧)
		//    schedule(schedule_selector(HelloWorld::myUpdate), 0.5);

		//---------------手动添加序列帧实现动画
		//    CCSprite* sp = CCSprite::create("crop1.png");
		//    sp->setPosition(ccp(170,200));
		//    addChild(sp);
		//    
		//    CCAnimation* animation = CCAnimation::create();
		//    animation->addSpriteFrameWithFileName("crop1.png");
		//    animation->addSpriteFrameWithFileName("crop2.png");
		//    animation->addSpriteFrameWithFileName("crop3.png");
		//    animation->addSpriteFrameWithFileName("crop4.png");
		//    animation->setDelayPerUnit(2.8f / 14.0f);//必须设置否则不会动态播放
		//    animation->setRestoreOriginalFrame(true);//是否回到第一帧
		//    animation->setLoops(-1);//重复次数(-1:无限循环)
		//    CCFiniteTimeAction * animate = CCAnimate::create(animation);
		//    sp->runAction(animate);

		//---------------通过资源文件创建动画
		CCTexture2D::PVRImagesHavePremultipliedAlpha(true);
		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("crop.plist");

		//利用帧缓存创建精灵
		CCSprite* sp = CCSprite::createWithSpriteFrameName("crop1.png");
		sp->setPosition(ccp(170,200));
		addChild(sp);

		CCArray* animFrames = CCArray::createWithCapacity(4);
		char str[100] = {0};
		for(int i = 1; i < 5; i++)
		{
			sprintf(str, "crop%i.png", i);
			CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
			animFrames->addObject(frame);
		}
		CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3f);
		animation->setLoops(-1);
		sp->runAction(CCAnimate::create(animation));

		//CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFrameByName("crop.plist");



<strong><span style="font-size:24px;color:#009900;">EffectTest(22种)</span></strong>

CCSize size=CCDirector::sharedDirector()->getWinSize();
		CCSprite* sp = CCSprite::create("Default.png");
		sp->setPosition(ccp(size.width*0.5,size.height*0.5));
		sp->setRotation(90);
		addChild(sp);

		//------ CCShaky3D
		    /*CCActionInterval* shaky3D = CCShaky3D::create(15, false, ccg(15,10), 4);
		    sp->runAction(shaky3D);*/

		//------ CCShakyTiles3D    
		    /*CCActionInterval* shakyTiles3D = CCShakyTiles3D::create(15, true, ccg(15,10), 4);
		    sp->runAction(shakyTiles3D);*/

		//------ CCWaves
		    /*CCActionInterval* waves = CCWaves::create(10, 20, true, true, ccg(16,12), 4);
		    sp->runAction(waves);*/

		//------ CCWaves3D
		    /*CCActionInterval* waves3D =CCWaves3D::create(10, 20, ccg(16,12), 3);
		    sp->runAction(waves3D);*/

		//------ CCWavesTiles3D
		    /*CCActionInterval* wavesTiles3D =CCWavesTiles3D::create(10, 20, ccg(16,12), 3);
		    sp->runAction(wavesTiles3D);*/

		//------ CCFlipX3D
		    /*CCActionInterval* flipX3D =CCFlipX3D::create(3);
		    sp->runAction(flipX3D);*/

		//------ CCFlipY3D
		    /*CCActionInterval* flipY3D =CCFlipY3D::create(3);
		    sp->runAction(flipY3D);*/

		//------ CCLens3D
		    /*CCActionInterval* lens3D =CCLens3D::create(CCPointMake(size.width/2,size.height/2), 240, ccg(15,10), 2);
		    sp->runAction(lens3D);*/

		//------ CCRipple3D
		    /*CCActionInterval* ripple3D =CCRipple3D::create(CCPointMake(size.width/2,size.height/2), 240, 4, 160, ccg(32,24), 3);
		    sp->runAction(ripple3D);*/

		//------ CCLiquid
		    /*CCActionInterval* liquid =CCLiquid::create(4, 20, ccg(16,12), 4);
		    sp->runAction(liquid);*/

		//------ CCTwirl 
		    /*CCActionInterval* twirl =CCTwirl::create(CCPointMake(size.width/2, size.height/2), 2, 2.5f, ccg(12,8), 3);
		    sp->runAction(twirl);*/ 

		//------ CCShuffleTiles
		    /*CCActionInterval* shuffleTiles =CCShuffleTiles::create(16, ccg(16,12), 2);
		    sp->runAction(shuffleTiles);*/

		//------ CCShatteredTiles3D    
		    /*CCActionInterval* shatteredTiles3D =CCShatteredTiles3D::create(25, true, ccg(16,12), 3);
		    sp->runAction(shatteredTiles3D);*/

		//------ CCFadeOutTRTiles
		    /*CCActionInterval* fadeOutTRTiles =CCFadeOutTRTiles::create(ccg(16,12), 2);
		    sp->runAction(fadeOutTRTiles);*/

		//------ CCFadeOutBLTiles
		    /*CCActionInterval* fadeOutBLTiles =CCFadeOutBLTiles::create(ccg(20,16), 2);
		    sp->runAction(fadeOutBLTiles);*/

		//------ CCFadeOutUpTiles
		   /* CCActionInterval* fadeOutUpTiles =CCFadeOutUpTiles::create(ccg(16,12), 3);
		    sp->runAction(fadeOutUpTiles);*/

		//------ CCFadeOutDownTiles
		    /*CCActionInterval* fadeOutDownTiles =CCFadeOutDownTiles::create(ccg(16,14), 3);
		    sp->runAction(fadeOutDownTiles);*/

		//------ CCTurnOffTiles 
		    /*CCActionInterval* turnOffTiles =CCTurnOffTiles::create(ccg(48,32) , 2);
		    sp->runAction(turnOffTiles);*/

		//------ CCJumpTiles3D
		    /*CCActionInterval* jumpTiles3D =CCJumpTiles3D::create(1, 30, ccg(15,10), 2);
		    sp->runAction(jumpTiles3D);*/

		//------ CCSplitRows
		    /*CCActionInterval* splitRows =CCSplitRows::create(10,2);
		    sp->runAction(splitRows);*/

		//------ CCSplitCols
		    /*CCActionInterval* splitCols =CCSplitCols::create(13, 3);
		    sp->runAction(splitCols);*/

		//------ CCPageTurn3D
		/*CCActionInterval* pageTurn3D =CCPageTurn3D::create(ccg(15,10), 3);
		sp->runAction(pageTurn3D);*/



<strong><span style="font-size:24px;color:#009900;">场景切换</span></strong>

CCScene* HelloWorld::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        HelloWorld *layer = HelloWorld::create();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
} 
上面代码就是创建了Helloworld这个场景,然后创建了一个层。再把这个层添加到场景中去
 
还记得我在init()函数中添加按钮的代码么...当我们添加了一按钮后,我们就可以修改它相对于的响应函数:
//添加场景切换控制按钮
		CCMenuItemImage *pCloseItem2 = CCMenuItemImage::itemWithNormalImage( 
			"b1.png",  
			"b2.png",
			this,  
			menu_selector(HelloWorld::menuTestCallback));
			CC_BREAK_IF(! pCloseItem2);  
		pCloseItem2->setPosition(ccp(size.width/2, size.height-100));

		CCMenu* pMenu2 = CCMenu::menuWithItems(pCloseItem2, NULL);
		pMenu2->setPosition(CCPointZero);  
		CC_BREAK_IF(! pMenu2);
		this->addChild(pMenu2, 1);
添加菜单...后面的那个1表示的是层次。最小的层在表面  
 
 
上面是init()中的代码。主要就是创建了一个按钮,然后放入菜单中。然后添加菜单进入场景中...下面是关键的切换特效实现代码...
 
void HelloWorld::menuTestCallback(CCObject* pSender)  
{  
	//注意这里的Scene(),这个是切换至什么场景,我这里写的就是本身这个场景,所以切来切去就是自己一个场景..哈哈,不过咱们看的是切换的过度特效嘛..  
	CCScene *scene = HelloWorld::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionJumpZoom::transitionWithDuration(1.2f,scene)); //->时间,场景 
}
正常的没有过度的场景切换,就是用CCDirector::sharedDirector()->replaceScene(scene);大家主要注意这个CCTransitionJumpZoom::,这个就是切换效果了!替换这个就能实现各种效果!

CCTransitionJumpZoom::transitionWithDuration(t, s);//跳跃式,本场景先会缩小,然后跳跃进来
CCTransitionFade::transitionWithDuration(t, s);//淡出淡入,原场景淡出,新场景淡入
CCTransitionFade::transitionWithDuration(t, s, ccWHITE);//如果上一个的函数,带3个参数,则第三个参数就是淡出淡入的颜色
CCTransitionFlipX::transitionWithDuration(t,s,kOrientationLeftOver);//x轴左翻
CCTransitionFlipX::transitionWithDuration(t,s,kOrientationRightOver);//x轴右翻
CCTransitionFlipY::transitionWithDuration(t,s,kOrientationUpOver);//y轴上翻
CCTransitionFlipY::transitionWithDuration(t,s,kOrientationDownOver);//y轴下翻
CCTransitionFlipAngular::transitionWithDuration(t,s,kOrientationLeftOver);//有角度转的左翻
CCTransitionFlipAngular::transitionWithDuration(t,s,kOrientationRightOver);//有角度转的右翻
CCTransitionZoomFlipX::transitionWithDuration(t,s,kOrientationLeftOver);//带缩放效果x轴左翻
CCTransitionZoomFlipX::transitionWithDuration(t,s,kOrientationRightOver);//带缩放效果x轴右翻
CCTransitionZoomFlipY::transitionWithDuration(t,s,kOrientationUpOver);//带缩放效果y轴上翻
CCTransitionZoomFlipY::transitionWithDuration(t,s,kOrientationDownOver);//带缩放效果y轴下翻 
CCTransitionZoomFlipAngular::transitionWithDuration(t,s,kOrientationLeftOver);//带缩放效果/有角度转的左翻
CCTransitionZoomFlipAngular::transitionWithDuration(t,s,kOrientationRightOver);//带缩放效果有角度转的右翻
CCTransitionShrinkGrow::transitionWithDuration(t, s);//交错换
CCTransitionRotoZoom::transitionWithDuration(t, s);//转角换
CCTransitionMoveInL::transitionWithDuration(t, s);//新场景从左移入覆盖
CCTransitionMoveInR::transitionWithDuration(t, s);//新场景从右移入覆盖
CCTransitionMoveInT::transitionWithDuration(t, s);//新场景从上移入覆盖
CCTransitionMoveInB::transitionWithDuration(t, s);//新场景从下移入覆盖
CCTransitionSlideInL::transitionWithDuration(t, s);//场景从左移入推出原场景
CCTransitionSlideInR::transitionWithDuration(t, s);//场景从右移入推出原场景
CCTransitionSlideInT::transitionWithDuration(t, s);//场景从上移入推出原场景
CCTransitionSlideInB::transitionWithDuration(t, s);//场景从下移入推出原场景以下三个需要检测opengl版本是否支持
CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0如果为真则为不支持
CCTransitionCrossFade::transitionWithDuration(t,s);//淡出淡入交叉,同时进行
CCTransitionRadialCCW::transitionWithDuration(t,s);//顺时针切入
CCTransitionRadialCW::transitionWithDuration(t,s);//逆时针切入以下两个需要先设置摄像机,使用
CCDirector::sharedDirector()->setDepthTest(true);
CCTransitionPageTurn::transitionWithDuration(t, s, false);//翻页,前翻
CCTransitionPageTurn::transitionWithDuration(t, s, true);//翻页,后翻
CCTransitionFadeTR::transitionWithDuration(t, s);//向右上波浪
CCTransitionFadeBL::transitionWithDuration(t, s);//向左下波浪
CCTransitionFadeUp::transitionWithDuration(t, s);//向上百叶窗
CCTransitionFadeDown::transitionWithDuration(t, s);//向下百叶窗
CCTransitionTurnOffTiles::transitionWithDuration(t, s);//随机小方块
CCTransitionSplitRows::transitionWithDuration(t, s);//按行切
CCTransitionSplitCols::transitionWithDuration(t, s);//按列切



<strong><span style="font-size:24px;color:#009900;">TouchTest</span></strong>
Init:
CCSprite* spr1 = CCSprite::create("Icon.png");
		spr1->setPosition(ccp(400,200));
		addChild(spr1);
		
		CCSprite * spr = CCSprite::create("Icon.png");
		spr->setPosition(ccp(150,150));
		addChild(spr,0,922);

		//back&menu
		setKeypadEnabled(true);



//重写触屏回调函数
	virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
	virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);

	//重写生命周期函数
	virtual void onEnter();
	virtual void onExit();

	//Menu&Back
	virtual void keyBackClicked();
	virtual void keyMenuClicked();

void HelloWorld::onEnter(){

	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
	CCLayer::onEnter();
}

void HelloWorld::onExit(){

	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
	CCLayer::onExit();
}

bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event){
	CCLOG("ccTouchBegan");
	return true;
}

void HelloWorld::ccTouchMoved(CCTouch* touch, CCEvent* event){
	CCLOG("ccTouchMoved");
}

void HelloWorld::ccTouchEnded(CCTouch* touch, CCEvent* event){
	CCLOG("ccTouchEnded");
	//获取离开屏幕时对应的坐标
	CCPoint point = touch->getLocation();

	//获取到精tag=922的精灵
	CCSprite* sp = (CCSprite*)this->getChildByTag(922);
	//暂停所有动作
	sp->stopAllActions();
	//执行move动作到用户离开时的位置
	sp->runAction(CCMoveTo::create(1, point));

}

//back&menu
void HelloWorld::keyBackClicked()
{
	CCLog("Back clicked!");
}

void HelloWorld::keyMenuClicked()
{
	CCLog("Menu clicked!");
}



<strong><span style="font-size:24px;color:#009900;">MutiTouchTest</span></strong>
 
//重写多触点回调函数
	virtual void registerWithTouchDispatcher(void);
	virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);

	//生命周期函数
	virtual void onExit();

//注册多触点的委托监听
void HelloWorld::registerWithTouchDispatcher(void){
	CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);
}

//用户手指第一次触碰
void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){
	CCSetIterator iter = pTouches->begin();
	for (; iter != pTouches->end(); iter++)
	{
		CCTouch* pTouch = (CCTouch*)(*iter);
		CCPoint location = pTouch->getLocation();
		if(pTouch->getID()==0){//第一个触点
			CCSprite * sp1 = (CCSprite*)this->getChildByTag(91);
			sp1->setPosition(location);            
		}else if(pTouch->getID()==1){//第二个触点
			CCSprite * sp2= (CCSprite*)this->getChildByTag(92);
			sp2->setPosition(location);
		}
	}
}
//用户手指进行移动或者拖拽
void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent){
	CCSetIterator iter = pTouches->begin();
	for (; iter != pTouches->end(); iter++)
	{
		CCTouch* pTouch = (CCTouch*)(*iter);
		CCPoint location = pTouch->getLocation();
		if(pTouch->getID()==0){//第一个触点
			CCSprite * sp1 = (CCSprite*)this->getChildByTag(91);
			sp1->setPosition(location);
		}else if(pTouch->getID()==1){//第二个触点
			CCSprite * sp2= (CCSprite*)this->getChildByTag(92);
			sp2->setPosition(location);
		}
	}
}
//用户手指抬起
void HelloWorld::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent){
	CCSetIterator iter = pTouches->begin();
	for (; iter != pTouches->end(); iter++)
	{
		CCTouch* pTouch = (CCTouch*)(*iter);
		CCPoint location = pTouch->getLocation();
		CCLOG("pTouch  触摸点%i 的坐标: x:%f,y:%f",pTouch->getID(),location.x,location.y);
	}
}

//删除多触点的委托监听
void HelloWorld::onExit(){
	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
	CCLayer::onExit();
}

Init:
//开启多触点监听务必调用此函数
		setTouchEnabled(true);

		CCSprite * sp1 = CCSprite::create("Icon.png");
		sp1->setColor(ccc3(255, 255, 0));//便于区分
		CCSprite * sp2 = CCSprite::create("Icon.png"); 
		sp1->setPosition(ccp(150,100));
		sp2->setPosition(ccp(150,200)); 
		addChild(sp1,0,91);
		addChild(sp2,0,92);



<strong><span style="font-size:24px;color:#009900;">RectCollisionTest</span></strong>

       
Init:
CCLayerColor*colorLayer = CCLayerColor::create(ccc4(0, 120, 255, 255), 480, 320);
		addChild(colorLayer);

		CCLabelTTF* pLabel1 = CCLabelTTF::create("~NO Collision~", "Thonburi", 24);
		pLabel1->setColor(ccc3(255, 0, 0));
		pLabel1->setPosition( ccp(size.width*0.5, size.height - 50) );
		this->addChild(pLabel1, 1,900);

		CCSprite*sp1 =CCSprite::create("rect1.png");
		sp1->setPosition(ccp(100,230));
		addChild(sp1,0,921);

		CCSprite*sp2 =CCSprite::create("rect2.png");
		sp2->setPosition(ccp(240,140));
		addChild(sp2,0,922);


virtual void onEnter();
virtual void onExit();
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

bool isRectCollision(CCRect rect1,CCRect rect2);


bool HelloWorld::isRectCollision(CCRect rect1,CCRect rect2){
	float x1 = rect1.origin.x;
	float y1 = rect1.origin.y;
	float w1 = rect1.size.width;
	float h1 = rect1.size.height;
	float x2 = rect2.origin.x;
	float y2 = rect2.origin.y;
	float w2 = rect2.size.width;
	float h2 = rect2.size.height;
	if(x1+w1*0.5<x2-w2*0.5){
		return false;

	}else if(x1-w1*0.5>x2+w2*0.5){
		return false;

	}else if(y1+h1*0.5<y2-h2*0.5){
		return false;

	}else if(y1-h1*0.5>y2+h2*0.5){
		return false;

	}
	return true;
}


bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
	CCSprite* sp1 =(CCSprite*)this->getChildByTag(921);
	sp1->setPosition(pTouch->getLocation());

	return true;
}

void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){

	CCSprite* sp1 =(CCSprite*)this->getChildByTag(921);
	sp1->setPosition(pTouch->getLocation());

	CCSprite*sp2 =(CCSprite*)this->getChildByTag(922);

	CCLabelTTF* pLabel = (CCLabelTTF*)this->getChildByTag(900);

	//    //利用自定义判断矩形碰撞函数
	//    if(this->isRectCollision(
	//                             CCRectMake(sp1->getPositionX(), sp1->getPositionY(), sp1->getContentSize().width, sp1->getContentSize().height),
	//                             CCRectMake(sp2->getPositionX(), sp2->getPositionY(), sp2->getContentSize().width, sp2->getContentSize().height))){
	//        pLabel->setString("碰撞拉!");
	//    }else{
	//        pLabel->setString("~还米有碰撞~");
	//    }

	//利用intersectsRect函数检测碰撞
	if(sp1->boundingBox().intersectsRect(sp2->boundingBox())){
		pLabel->setString("Collision!");
	}else{
		pLabel->setString("~No Collision~");
	}
}

void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){


}

void HelloWorld::onEnter(){
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
	CCLayer::onEnter();
}

void HelloWorld::onExit(){
	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
	CCLayer::onExit();
}



<strong><span style="font-size:24px;color:#009900;">CircleCollisionTest</span></strong>

  
Init:
/*CCLayerColor * color = CCLayerColor::create(ccc4(255, 255, 255, 255), 480, 320);
		addChild(color);*/

		CCLabelTTF* pLabel1 = CCLabelTTF::create("NO collision ^. ^", "Helvetica", 24);
		pLabel1->setColor(ccRED);
		pLabel1->setPosition( ccp(size.width*0.5, size.height-50) );
		this->addChild(pLabel1, 0, 920);

		CCSprite* sp1 = CCSprite::create("circle1.png");
		sp1->setPosition(ccp(100,170));
		addChild(sp1,0,921);

		CCSprite* sp2 = CCSprite::create("circle2.png");
		sp2->setPosition(ccp(350,170));
		addChild(sp2,0,922);


virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

virtual void onEnter();
virtual void onExit();

bool isCircleCollision(CCPoint pos1,float radius1,CCPoint pos2,float radius2 );


bool HelloWorld::isCircleCollision(CCPoint pos1,float radius1,CCPoint pos2,float radius2){

	if(sqrt(pow(pos1.x-pos2.x, 2)+pow(pos1.y-pos2.y, 2))>radius1+radius2){
		return false;
	}
	return true;
}

bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
	CCPoint touchPoint = pTouch->getLocation();
	CCSprite* sp1 = (CCSprite*)this->getChildByTag(921);
	sp1->setPosition(touchPoint);
	return true;
}

void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){
	CCPoint touchPoint = pTouch->getLocation();
	CCSprite* sp1 = (CCSprite*)this->getChildByTag(921);
	CCSprite* sp2 = (CCSprite*)this->getChildByTag(922);
	CCLabelTTF* ttf = (CCLabelTTF*)this->getChildByTag(920);
	if(this->isCircleCollision(sp1->getPosition(), sp1->getContentSize().width*0.5, sp2->getPosition(), sp2->getContentSize().width*0.5)){
		ttf->setString("Collision =w=||");
	}else{
		ttf->setString("No Collision ^. ^");
	}
	//
	sp1->setPosition(touchPoint);
}
void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){


}

void HelloWorld::onEnter(){
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
	CCLayer::onEnter();
}

void HelloWorld::onExit(){
	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
	CCLayer::onExit();
}



<strong><span style="font-size:24px;color:#009900;">parallaxNode</span></strong>
 
CCSprite* spFont = CCSprite::create("front.png");
		CCSprite* spMiddle = CCSprite::create("middle.png");
		CCSprite* spFar = CCSprite::create("far.png");

		CCParallaxNode * parallaxNode = CCParallaxNode::create();
		addChild(parallaxNode);

		//近景
		parallaxNode->addChild(spFont,3, ccp(4.8f,0), ccp(spFont->getContentSize().width*0.5,spFont->getContentSize().height*0.5) );
		//中景
		parallaxNode->addChild(spMiddle, 2, ccp(1.6f,0), ccp(spMiddle->getContentSize().width*0.5,spMiddle->getContentSize().height*0.5+spFont->getContentSize().height*0.5) );
		//远景
		parallaxNode->addChild(spFar, 1, ccp(0.5f,0), ccp(spFar->getContentSize().width*0.5,spFar->getContentSize().height*0.5+spFont->getContentSize().height*0.5+spMiddle->getContentSize().height*0.5) );


		CCActionInterval* go = CCMoveBy::create(8, ccp(-200,0) );
		CCActionInterval* goBack = go->reverse();
		CCFiniteTimeAction* seq = CCSequence::create(go,goBack, NULL);
		parallaxNode->runAction( (CCRepeatForever::create((CCActionInterval*) seq) ));


<strong><span style="font-size:24px;color:#009900;">MusicText</span></strong>


//menuitem回调函数
	void menuBack(CCObject * pSender);
	//用以记录音效ID
	int effectId ;

void HelloWorld::menuBack(CCObject * pSender)
{
	CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);
	int nIdx = pMenuItem->getZOrder() ;
	switch(nIdx)
	{
	case 0:
		//播放背景音乐
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str(), true);
		break;
	case 1:
		//停止背景音乐
		SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
		break;
	case 2:
		//暂停背景音乐
		SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
		break;
	case 3:
		//继续播放背景音乐
		SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
		break;
	case 4:
		//后退背景音乐
		SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
		break;
	case 5:
		//背景音乐是否正在播放
		if (SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()){
			CCLOG("背景音乐正在播放");
		}else{
			CCLOG("背景音乐没在播放");
		}
		break;
	case 6:
		//播放音效,并且得到此音效的ID
		effectId = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str());
		break;
	case 7:
		//重复播放音效
		effectId = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str(), true);
		break;
	case 8:
		//停止音效播放
		SimpleAudioEngine::sharedEngine()->stopEffect(effectId);
		break;
	case 9:
		//释放音效
		SimpleAudioEngine::sharedEngine()->unloadEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str());
		break;
	case 10:
		//增加背景音乐的音量
		SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() + 0.1f);
		break;
	case 11:
		//减少背景音乐的音量
		SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() - 0.1f);
		break;
	case 12:
		//增加音效的音量
		SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume() + 0.1f);
		break;
	case 13:
		//减少音效的音量
		SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume() - 0.1f);
		break;
	case 14:
		//暂停音效
		SimpleAudioEngine::sharedEngine()->pauseEffect(effectId);
		break;
	case 15:
		//继续播放音效
		SimpleAudioEngine::sharedEngine()->resumeEffect(effectId);
		break;
	case 16:
		//暂停所有音效
		SimpleAudioEngine::sharedEngine()->pauseAllEffects();
		break;
	case 17:
		//继续所有音效
		SimpleAudioEngine::sharedEngine()->resumeAllEffects();
		break;
	case 18:
		//停止所有音效
		SimpleAudioEngine::sharedEngine()->stopAllEffects();
		break;
	}

}


#include "SimpleAudioEngine.h"

using namespace cocos2d;
using namespace CocosDenshion;

//根据不同平台使用预编译索引不同音频文件
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#define EFFECT_FILE        "effect2.ogg"
#elif( CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
#define EFFECT_FILE        "effect1.raw"
#else
#define EFFECT_FILE        "effect1.wav"
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#define MUSIC_FILE        "music.mid"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY)
#define MUSIC_FILE        "background.ogg"
#else
#define MUSIC_FILE        "background.mp3"
#endif

std::string items[] = {
	"播放背景音乐","停止背景音乐","暂停背景音乐",
	"继续背景音乐","后退背景音乐","背景音乐是否正在播放",
	"播放音效","重复播放音效","停止音效","释放音效",
	"增加背景音乐音量","减少背景音乐音量",
	"增加音效音量","减少音效音量","暂停音效",
	"继续播放音效","暂停所有音效","继续所有音效",
	"停止所有音效"
};



Init:
CCMenu* m_pItmeMenu = CCMenu::create();
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		int m_nTestCount = sizeof(items) / sizeof(items[0]);

		for (int i = 0; i < m_nTestCount; i++)
		{
			CCLabelTTF* label = CCLabelTTF::create(items[i].c_str(), "Arial", 15);

			CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::menuBack));

			m_pItmeMenu->addChild(pMenuItem, i);
			pMenuItem->setPosition( CCPointMake(0, (s.height*0.5-20- (i + 1) * 15) ));
		}
		addChild(m_pItmeMenu,0,100);
		//预加载音乐和音效
		SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( MUSIC_FILE );
		SimpleAudioEngine::sharedEngine()->preloadEffect( EFFECT_FILE );
		//设置默认音量
		SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.5);
		SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(1.5);



<strong><span style="font-size:24px;color:#009900;">ParticleTest</span></strong>
//--------------------------自带的种粒子效果
		    //---爆炸粒子效果
		   /* CCParticleSystem* particleSyetem = CCParticleExplosion::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("stars.png"));*/
		 
		    //---火焰粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleFire::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---花束粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleFlower::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---烟花粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleFireworks::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---星系粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleGalaxy::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---流星粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleMeteor::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---下雨粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleRain::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---烟雾粒子效果
		   /* CCParticleSystem* particleSyetem = CCParticleSmoke::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---下雪粒子效果
		   /* CCParticleSystem* particleSyetem = CCParticleSnow::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("snow.png"));*/
		 
		    //---漩涡粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleSpiral::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    //---太阳粒子效果
		    /*CCParticleSystem* particleSyetem = CCParticleSun::create();
		    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));*/
		 
		    /*particleSyetem->setPosition(ccp(240,160));
		    addChild(particleSyetem);*/


		//-----------------------------函数、移动类型对比

		//    CCParticleSystem* particleSyetemFree = CCParticleSun::create();
		//    //设置贴图
		//    particleSyetemFree->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));
		//    //设置自动释放
		//    particleSyetemFree->setAutoRemoveOnFinish(true);
		//    //设置移动类型kCCPositionTypeFree
		//    particleSyetemFree->setPositionType(kCCPositionTypeFree);
		//    particleSyetemFree->setPosition(ccp(90,160));
		//    addChild(particleSyetemFree);
		//    
		//    CCParticleSystem* particleSyetemRel = CCParticleSun::create();
		//    particleSyetemRel->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));
		//    //设置移动类型kCCPositionTypeRelative
		//    particleSyetemRel->setPositionType(kCCPositionTypeRelative);
		//    particleSyetemRel->setPosition(ccp(200,160));
		//    addChild(particleSyetemRel);
		//    
		//    //让当前layer来回移动,观察两个移动模式不同的粒子特效
		//    CCFiniteTimeAction * move = CCMoveBy::create(3, ccp(290,0));
		//    CCFiniteTimeAction* back = move->reverse();
		//    this->runAction(CCSequence::create(move,back,NULL));


		//---------------------------创建自定义粒子
		   /* CCParticleSystem* myParticle = CCParticleSystemQuad::create("himiParticle.plist");
		    addChild(myParticle);*/

		//---------------------------CCParticleBatchNode
		    //不使用CCParticleBatchNode
		    /*for (int i =0 ; i<10; i++) {
		        CCParticleSystem* particleSyetem = CCParticleSun::create();
		        particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));
		        particleSyetem->setPosition(ccp(150+i*20,160));
		        addChild(particleSyetem);
		    }*/

		//使用CCParticleBatchNode
		/*CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("fire.png");
		CCParticleBatchNode* particleNode =CCParticleBatchNode::createWithTexture(texture);
		for (int i =0 ; i<10; i++) {
			CCParticleSystem* particleSyetem = CCParticleSun::create();
			particleSyetem->setTexture(texture);
			particleSyetem->setPosition(ccp(150+i*20,160));
			particleNode->addChild(particleSyetem);
		}
		addChild(particleNode);*/



<strong><span style="font-size:24px;color:#009900;">菜单划屏浏览</span></strong>
 
Init:
//----CCMenuItemSprite
		CCSprite* spNor = CCSprite::create("Icon.png");
		spNor->setColor(ccc3(255, 255, 0 ));
		CCSprite* spSelected =CCSprite::create("Icon.png");
		CCMenuItemSprite* spriteItem = CCMenuItemSprite::create(spNor,spSelected, this,NULL);
		spriteItem->setPosition(ccp(-80,-20));

		m_pItemMenu = CCMenu::create(spriteItem,NULL);
		addChild(m_pItemMenu);



virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);

private:
	CCPoint m_tBeginPos;
	CCMenu* m_pItemMenu;


void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	m_tBeginPos = touch->getLocation();    
}

void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
	CCSetIterator it = pTouches->begin();
	CCTouch* touch = (CCTouch*)(*it);

	CCPoint touchLocation = touch->getLocation();    
	float nMoveY = touchLocation.y - m_tBeginPos.y;

	CCPoint curPos  = m_pItemMenu->getPosition();
	CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	if (nextPos.y < 0.0f)
	{
		m_pItemMenu->setPosition(CCPointZero);
		return;
	}

	/*if (nextPos.y > ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height))
	{
		m_pItemMenu->setPosition(ccp(0, ((TESTS_COUNT + 1)* LINE_SPACE - winSize.height)));
		return;
	}*/

	m_pItemMenu->setPosition(nextPos);
	m_tBeginPos = touchLocation;
	//s_tCurPos   = nextPos;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值