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

【Cocos2d-x 粒子系统】火球随手指飞起来_第1张图片

程序:

创建球

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

	} 
}


你可能感兴趣的:(cocos2d-x)