Ensure that the fire.png file exists in the project because the cocos2D particle system needs to be used. Otherwise, the color will only display the black box.
1. Use the built-in particle effect to spray blood after hitting the enemy with a finger bullet
CCParticleSystem * system;
System = [CCParticleExplosion node]; // explosive effect (there are many other effects)
// Display the effect on the currently played genie
System. position = CGPointMake (self. contentSize. width/2, self. contentSize. height/2 );
System. lift = 0.2; // the lifecycle of a particle disappears after 0.2 seconds.
System. lifeVar = 0; // the change in the life cycle of the particle. The lifecycle is obtained by adding and subtracting the random and upper values. Here, the change is not allowed, so it is 0.
System. startSize = 5; // particle size when the original file is created
System. startSizeVar = 0; // The change level is still 0.
System. endSize = 1; // The size at the end of the particle Lifecycle
System. endSizeVar = 0; // The change level is still 0.
CcColor4F c = {1.0, 0, 0, 1}; // defines that the particle color is red and opaque.
System. startColor = c; // The starting color of the particle is red.
System. startColorVar = c;
System. endColor = c; // The ending color of the particle is red.
System. endColorVar = c;
System. autoRemoveOnFinish = YES: // After the animation effect is executed, it is automatically removed from the parent node.
[Self addChild: system z: 1 tag: 1]; // The animation is automatically removed after being added as a child node and is automatically removed after the animation is completed. You do not need to manage the animation.
System. autoRemoveOnFinish = YES: // After the animation effect is executed, it is automatically removed from the parent node.
[Self addChild: system z: 1 tag: 1]; // The animation is automatically removed after being added as a child node and is automatically removed after the animation is completed. You do not need to manage the animation.
Compile and run the program to see the effect.
2. Use resource source files to achieve particle effect
Download the particle designer tool-> open it and click Randomie to view some of the effects of others. You can find a similar parameter to modify the corresponding parameter. Save it as the monsterOver1.plist file.
After adding the monsterOver1.plist file to the project, this file is used to show the explosion effect after the enemy is killed.
CCParticleSystem * system;
System = [CCParticleSystemQuad participant lewithfile: @ "monsterOver1.plist"];
CGPoint location = CGPointMake (self. contentSize. width/2, self. contentSize. height/2); // The coordinates are detailed below the local coordinates.
Location = [self convertToWorldSpace: location]; // convert it to the world coordinate system
Location = [self. parent. parent convertToNodeSpace: location]; // because the explosion effect is displayed at the scene layer, convert the world coordinates to the coordinates of the scene.
System. position = location;
System. autoRemoveOnFinish = YES: // After the animation effect is executed, it is automatically removed from the parent node.
[Self addChild: system z: 1 tag: 1]; // The animation is automatically removed after being added as a child node and is automatically removed after the animation is completed. You do not need to manage the animation.
Compile and run the program to see the effect.
3. cocos2d coordinate system usage and conversion method (Abstract