有时候我们需要做一些特殊的效果,比如子弹爆炸的效果,但是有时候发现利用粒子的效果去代替它会跟好看,所以现在我们要介绍的就是cocos2dx粒子效果。我们先来看下粒子代码:
- [cpp]
- void ParticleDemoLayer::initLayer()
- {
- CCSize size = CCDirector::sharedDirector()->getWinSize();
- m_pParticleWorld = CCParticleFlower::create();//创建你想创建的粒子效果
- m_pParticleWorld->retain();
- m_pParticleWorld->setTexture(CCTextureCache::sharedTextureCache()->addImage("r2.png"));
- m_pBground = CCSprite::create("background3.png");
- m_pBground->setAnchorPoint(ccp(0.5f, 0.5f));
- m_pBground->setPosition(ccp(size.width / 2.0f, size.height / 2.0f));
- this->addChild(m_pBground, 4);
- if(m_pParticleWorld != 0) {
- m_pParticleWorld->setAnchorPoint(ccp(0.5f, 0.5f));
- m_pParticleWorld->setPosition(size.width / 2.0f, size.height / 2.0f);
- m_pBground->addChild(m_pParticleWorld, 5);
- }
- }
- [cpp]
- CCParticleFlower,继承的CCParticleSystemQuad的,在Cocos2dx中,它提供了几种效果类,想研究得可以去看下源码,在examples.h文件中