O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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 particle systems to our game

Cocos2d-x has built-in classes that allow you to render the most common visual effects such as explosions, fire, fireworks, smoke, and rain, among others, by displaying a large number of small graphic objects referred to as particles.

It is very easy to implement. Let us add a default explosion effect, by simply adding the following lines to our explodeBombs method:

bool HelloWorld::explodeBombs(cocos2d::Touch* touch, cocos2d::Event* event){
  Vec2 touchLocation = touch->getLocation();
  cocos2d::Vector<cocos2d::Sprite*> toErase;
  for(auto bomb : _bombs){
    if(bomb->getBoundingBox().containsPoint(touchLocation)){
      auto explosion = ParticleExplosion::create(); explosion->setPosition(bomb->getPosition()); this->addChild(explosion); ...

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