Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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 the width of the character to it so that it gets created at the nozzle of the gun and not at the center of the player.

Then, we set the starting color of the particle to white. The setStartColor...