Cocos2d-x Introduction

Source: Internet
Author: User
Tags stack pop


CCPoolManagerIs a single class that manages multiple garbage collection objects. CCArray * m_pReleasePoolStack can manage multiple garbage collectors. CCPoolManager uses getCurReleasepool to obtain the current Garbage Collector m_pCurReleasePool. If m_pCurReleasePool = NULL, call push to create a new Garbage Collector and add it to the m_pReleasePoolStack. The Pop method clears the current Garbage Collector m_pCurReleasePool, and then releases a new setting for the stack pop to be used by the current garbage collector.


CCAutoreleasePoolThe automatic garbage collector manages added CCObject objects through a dynamic array autorelease.


CCApplicationIs the main application class of the Cocos2d-x, the application must inherit this CCApplication, in the main function need to define a CCApplication object and execute its run method.


CCDirectorThe director class is mainly used for scenario management and scheduling. It is initialized by creating CCActionManagement Object Manager, touch message distributor, Keyboard Message distributor, accelerator, and a series of other methods, the CCPoolManager that we just mentioned also needs to be used to create a garbage collector.

The most important method isMainLoopThis method is similar to the mainLoop in openGL and glut libraries. The steps are rendering scenarios. Release the current garbage collector, but it is implemented through CCPoolManager, while opengl is implemented through glClear.


CCNode class, which is the most important member method:

Create and release: onEnter (), onExit ()

Add and delete sub-objects: addchild (), removeChild ()

Return space of the rectangle: bounddingBox (void );

Run related actions: runAction (), runAllAction (), stopAction (), and so on.

There are also important rendering padding: draw (), visit (), transform ()

The custom drawing of the CCNote object must be implemented in the draw method, because the engine sets the status of the drawing environment in the context of the function call.


Scheduling mechanism: Add by registering the scheduler method, or use the CCNote: scheduleUpdate method.

First: in fact, it is actually implemented by calling the scheduler monomer, which is generated during CCDirector initialization and set in the CCNote constructor for CCNote.

The registration and scheduling of scheduling workers is mainly to create a timer CCTimer object and add the CCNote object and scheduler handler to the timer object for later scheduling.


Garbage collection mechanism:Similar to java's garbage collection mechanism, it is essentially a reference counting mechanism for the base class CCObject.

When CCObject is initialized, the reference count is set to 1. If retain is added, the release value is reduced by one.

In addition, the main task of mainLoop is to render the scenario, release and clear the current garbage through CCPoolManager (see the above running mechanism)



Related Article

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: 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.