O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition 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 particle effect

You can also add particle effects to the game with a few lines of code.

Getting ready

To create the particle effect, we need to import the image file that will be used by the effect first of all. In this case, it is the fire.png file. Import it into the project.

How to do it…

To add the particle effect to the project, we will add the following to the bottom of the init function right after the MainScene.m file:

        CCParticleFire* fire = [[CCParticleFire alloc]initWithTotalParticles:20];

        fire.position = CGPointMake(winSize.width/2, winSize.height/2);

        [self addChild:fire];

Here, we created a fire effect, so we used CCParticleFire to create the particle system. While initializing the particle system, we need to pass in the number ...

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