Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – creating particle systems


For particles, all we need is the XML file describing the particle system's properties.

  1. So let's go to GameLayer.cpp.

  2. The game initializes by calling createGameScreen, which is already in place, then createParticles and createStarGrid, which is also implemented. So let's go over the createParticles method now.

  3. Go to that method in GameLayer.cpp and add the following code:

    _jet = ParticleSystemQuad::create("jet.plist");
    _jet->setSourcePosition(Vec2(-_rocket->getRadius() * 0.8f,0));
    _jet->setAngle(180);
    _jet->stopSystem();
    this->addChild(_jet, kBackground);
    
    _boom = ParticleSystemQuad::create("boom.plist");
    _boom->stopSystem();
    this->addChild(_boom, kForeground);
    
    _comet = ParticleSystemQuad::create("comet.plist");
    _comet->stopSystem();
    _comet->setPosition(Vec2(0, _screenSize.height * 0.6f));
    _comet->setVisible(false);
    this->addChild(_comet, kForeground);
    
    _pickup = ParticleSystemQuad::create("plink.plist");
    _pickup-...