Particle System for cocos2d-x Learning

Source: Internet
Author: User
Tags case statement switch case

The tests project in the cocos2d-x is rich in content, one of the most dazzling test is the participation test, this test contains 43 different particle rendering effect, a good interpretation of the cocos2d-x particle system.

Find the callback function menucallback in controller. cpp. This function is called when the List entry of the touch main interface is used to enter the corresponding test instance. Code:

    // get the userdata, it's the index of the menu item clicked    CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);    int nIdx = pMenuItem->getZOrder() - 10000;    // create the test scene and run it    TestScene* pScene = CreateTestScene(nIdx);    if (pScene)    {        pScene->runThisTest();        pScene->release();    }

Obtain the index of the touch entry, create a scenario, and run runthistest.

Look at the createtestscene (nidx) function, where a switch case statement is used to create a test scenario for the response based on the index.

Find the particle testscene (), which is the scenario of the particle system.

The runthistest () function of the execution scenario is used after the scenario is created.

    addChild(nextParticleAction());    CCDirector::sharedDirector()->replaceScene(this);

The code is very simple. There are only two sentences. Add a set and change the director's scenario.

Look at the nextparticipant action () function, which creates different sets.

    sceneIdx++;    sceneIdx = sceneIdx % MAX_LAYER;    CCLayer* pLayer = createParticleLayer(sceneIdx);    pLayer->autorelease();    return pLayer;

We can see that the particle test contains 43 instances. Use switch-case to create an index.

First come here, and then read the code of each particle instance.


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.