【Cocos2d-x 粒子系统】火球用手指飞起来

程序:

创建球

	sp1 = CCSprite::create("ball.png");
	sp1->setPosition(ccp(10, visibleSize.height/2));
	this->addChild(sp1);
	setTouchEnabled(true);

让球飞起来吧,创建个简单粒子,点哪飞到哪

void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();  
	if (sp1) { 
		//获取点击位置转GL
		CCPoint location = pTouch->getLocationInView();  
		CCPoint pos = CCDirector::sharedDirector()->convertToGL(location);  
		CCLOG("ccTouchEnded...x:%f y:%f", pos.x, pos.y); 

		//创建粒子系统,设置參数
		CCParticleSystem *cps = CCParticleSun::create();
		cps->retain();
		cps->setPosition(ccp(0,5));//位置
		cps->setLife(0.06f);//每个粒子的生命周期
		sp1->addChild(cps);//添加到图层向导
		CCActionInterval *by = CCMoveTo::create(1, ccp(pos.x, pos.y)); //移动
		sp1->runAction(by);

	} 
}


posted @ 2015-12-16 18:11  mfrbuaa  阅读(370)  评论(0编辑  收藏  举报