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.