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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.