Adding the gun muzzle particle system

You can add the previous code in the fireRocket function in the HelloWorldScene.cpp file and then build and run it. You will see the particles getting generated at the origin, but the explosion is a bit huge and looks very colorful. Let's make some changes so that it looks like a muzzle smoke.

Between the create and addchild functions, add the following:

   m_emitter->setPosition(ccpAdd(hero->getPosition(), ccp(hero->getContentSize().width/2 ,0 )));
   
   m_emitter->setStartColor(ccc4f(1.0, 1.0, 1.0, 1.0));
   m_emitter->setEndColor(ccc4f(0.0, 0.0, 0.0, 0.0));
   
   m_emitter->setTotalParticles(10);
   m_emitter->setLife(0.25);
   m_emitter->setSpeed(2.0);
   m_emitter->setSpeedVar(30.0);

We take the current position of the hero and add ...

Get Learning Cocos2d-x Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.