Cocos2d particle effect and learning of particle designer particle Tool

Source: Internet
Author: User

I recently learned about the particle effect in cocos2d. Let's share what I learned with you!

Now! Let's first understand the class structure.

-- Ccparticlesystem (parent class of all particle systems)

-- Ccparticlesystempoint and ccparticlesystemquad (point particle and square particle system both inherit all attributes of ccparticlesystem)

-- Ccparticleexplosion (particle blast effect)

-- Ccparticlefireworks (Fireworks)

-- Ccparticlefire (flame particle effect)

-- Ccparticleflower (bouquet particle effect)

-- Ccparticlegalaxy (Galaxy particle effect)

-- Ccparticlemeteor (meteor particle effect)

-- Ccparticlespiral (vortex particle effect)

-- Ccparticlesnow (snow particle effect)

-- Ccparticlesmoke (smoke particle effect)

-- Ccparticlesun (Sun particle effect)

-- Ccparticlerain (rain particle effect)

Okay, basically there are so many things. Both are cocos2d built-in particle systems, which are quite powerful. The key is not to play with these classes, but the attributes of the particle system. The attributes depend on N. For the time being, I will talk about a tool (particle designer) later, which is very convenient and saves a lot of trouble. Now let's understand something first.

1. ccparticlesystempoint and ccparticlesystemquad

Most particle systems inherit one of these two systems. Which one should they inherit? Let's analyze:

Ccparticlesystempoint: the particle system consumes less memory and runs faster. However, it only means that the performance after generation 3 is not good on generations 1 and 2.

Ccparticlesystemquad: The square particle system runs faster on machines after 3 generations and consumes more memory and CPU.

Each has its own advantages and disadvantages! So can we choose the best particle system based on different machines in the code?

The answer is yes.

Use the pre-processor arch_optimal_particle _system to define the particle system and determine which particle system to use during code compilation. The appropriate particle system will be automatically selected based on the model.

Example: @ interface ccparticleexplosion: arch_optimal_participant le_system

2. Particle maps

The particle texture must be smaller than 64x64. The smaller the particle texture, the better.

You can embed a texture into the particle designer (Disadvantage: it is inconvenient to modify the texture), or import self. Texture = [[cctexturecachesharedtexturecache] addimage: Participant file] to the project.

Now, let's take a look at particle designer, a visual Property Tuning tool. : Http://particledesigner.71squared.com. How to use this tool is not detailed, open this tool at a glance. This article describes how to use this tool to export files in the project.

1. Click Save in the tool, save it as a. plist file, and then import the file to the project (not to mention the basics ).

2. Then instantiate the particle object (arch_optimal_particle _system must be used for initialization here. If the parent class ccparticlesystem is used, nothing will be seen)

Ccparticlesystem * system;

System = [maid "fx-explosion.plist"];

[Self addchild: System Z: 1 Tag: 1];

3. OK. You can modify the attributes that cannot be modified in the tool.

System. positiontype = kccpositiontypefree;

System. autoremoveonfinish = yes; // removed from the parent node after the particles disappear.

System. Position = CCP (100,100); // The Position of the particle transmitter.

Note that the positiontype attribute is used. Refer to the himi tutorial, where the particle changes with the position of the genie. This depends on the setting of this attribute. There are three values:

In the relative mode of kccpositiontyperelative, the particle transmitter moves with the genie and can be used to create special effects on the role.

Kccpositiontypegrouped has the same effect as the above (Experimental Results). The difference is that the particle moves with the transmitter.

The kccpositiontypefree mode does not move with the particle node (flame, steam, and other effects can be produced)

4. Finally, let's talk about the problem we encountered during the test. When we want to display the particle effect, there will be a slight card on the interface, which is the particle loading the texture resource. If this problem is not solved, the game may become unstable. Here we can use the pre-loading mechanism. This method is also learned in the tutorial! Learning is everywhere!

First, we add [self preloadparticle effect] to the initialization init of the game entry scenario;

-(Void) preloadparticipant leeffect

{

[Maid "fx-explosion.plist"];

}

Because the particle file method is initialized in the form of automatic release, there is no need to worry about their memory release issue.

After they are released, their textures will be retained in the cctexturecache, which solves the problem of loading textures in time during particle display.

If there is no embedded texture in the "fx-explosion.plist", use [[cctexturecachesharedtexturecache] addimage "fire.png"]; this method adds the texture to the cache first.

To adjust the effect, you need to use your own tools. It seems not that easy... Come on! If you have any questions to add, let's take a look...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.