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);
bomb->setVisible(false);
this->removeChild(bomb);
toErase.pushBack(bomb);
}
}
for(auto bomb : toErase){
_bombs.eraseObject(bomb);
}
return true;
}
You...