Cocos2d-JS built-in Particle System

Source: Internet
Author: User

Cocos2d-JS built-in Particle System
From the class diagram we can see that there are 11 built-in particles in the Cocos2d-JS, the attributes of these particles are pre-defined, we can also modify some attributes in the program code, these attributes have been set in the instance in the previous section.
Built-in Particle System
11 built-in particle systems are described as follows:
You can call this operation to create a project. The particle blast effect belongs to the radius mode.
You can call this operation to create a project. Flame particle effect, which belongs to the gravity path mode.
You can call this operation to create a project. Fireworks particle effect, which belongs to the gravity mode.
. The particle effect is a gravity mode.
The sample code is as follows. Galaxy particle effect, which belongs to the radius mode.
You can call this operation to perform the following operations. Meteor particle effect, which belongs to the gravity mode.
You can call this operation to create a project. Vortex particle effect, which belongs to the radius mode.
The name of the object. The snow particle effect belongs to the gravity mode.
. Smoke particle effect, which belongs to the gravity mode.
. The effect of the Sun particles belongs to the gravity mode.
You can call this operation to perform operations on the object. Rain particle effect, which belongs to the gravity mode.
The properties of these 11 kinds of particles vary depending on their emission modes.
Example: built-in Particle System
The following example shows the 11 built-in particle systems. In this example, the left figure shows an operation menu scenario. You can select the menu to go to the action scenario. In the action scenario, the effect of the selected particle system is displayed. Click the return button in the lower right corner to return to the menu scenario.

The built-in Particle System example below focuses on the scenario MyActionScene. Its MyActionScene. js code is as follows:

Var MyActionLayer = cc. layer. extend ({flagTag: 0, // operation flag pLabel: null, ① ctor: function (flagTag) {this. _ super (); this. flagTag = flagTag; cc. log (MyActionLayer init flagTag + this. flagTag); var size = cc. director. getWinSize (); var backMenuItem = new cc. labelBMFont (
 
  
In the header file, line ① defines the LabelBMFont member variable pLabel, which is used to display the particle system name in the scene. We create a particle system object in the onEnterTransitionDidFinish function of MyActionLayer, instead of creating the onEnter function of MyActionLayer. This is because the scenario is not displayed when the onEnter function of MyActionLayer is called, if you create an explosion in this function to display the particle system once, and wait until the scene shows that the explosion has ended, we will not see the effect. Code ② ~ Line 4 creates 11 types of particle systems. Here, their default attribute values are used when creating particle systems. Here, the this. pLabel. setString (XXX) function sets the content for the tags in the scenario, so that the name of the particle system is displayed after entering the scenario.
  

In addition, if you need to add a texture to the particle system when running in a Web browser, we only add the fire particle texture in line 3 of the Code, and add other particle textures similarly.

 

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.