O'Reilly logo

Learning Cocos2d-x Game Development by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required