[COCOS2DX]COCOS2DX Main class

Source: Internet
Author: User
Tags addchild in degrees

CcobjectCCObject.h:
#ifndef __ccobject_h__#define __ccobject_h__#include "platform/ccplatformmacros.h"//cocos2d namespace ns_cc_begin// Declares the following kinds of pointers to the member variables of the corresponding class, which are later defined. The following classes are derived classes of the Ccobject class.  Class Cczone;  Ccobject pointer staging class ccobject;//base class Ccnode; node classes class Ccevent; Event class//This defines a copy class class Cc_dll cccopying{public://virtual function. The function is to copy a new Ccobject object pointer to the object pointed to by the Cczone pointer virtual ccobject* copywithzone (cczone* pzone);};/    /derived from cccopying ccobjectclass cc_dll ccobject:public cccopying{public://Unique ID unsigned intm_uid;    The Access ID ID in the LUA scripting engine. Temporarily ignore, when learning to Lua, then analyze the int m_nluaid;protected://reference counter, memory count.    unsigned intm_ureference;    Whether it is being managed by the memory manager and automatically released.    boolm_bmanaged;public://constructor Ccobject (void);//destructor virtual ~ccobject (void); release void release (void);//leave void retain (void);//Set the release of the instance object to be managed by the memory manager.    For automatic release. ccobject* autorelease (void);//obtain a copy ccobject* copy (void);//Whether the instantiated object of this class has only one user bool issinglerefrence (void);//    Returns the value of the memory counter, that is, the number of users unsigned int retaincount (void);  Determine if the same as another Ccobject instance object  virtual bool IsEqual (const ccobject* pobject);    Update function virtual void update (Cctime dt) {cc_unused_param (dt);}; Set Cautoreleasepool as a friend class, which is a class that manages the memory of Ccobject instance objects through the Ccobject pointer container ccmutablearray.    Ccmutablearray adds 1 to its reference counter when adding Ccobject, minus 1 on its reference counter when removing ccobject. Friend Class ccautoreleasepool;};/ /define some functions//define Timer Access class member function typedef void (ccobject::* sel_schedule) (cctime);//define generic callback class member function typedef void (ccobject::* sel_ CALLFUNC) (//);//define a callback class with a node parameter as a function typedef void (ccobject::* sel_callfuncn) (ccnode*);//define a callback class member function typedef with a node parameter and 1 user value parameters void (ccobject::* sel_callfuncnd) (ccnode*, void*), typedef void (ccobject::* Sel_callfunco) (ccobject*);// Define menu Response class member function typedef void (ccobject::* Sel_menuhandler) (ccobject*);//define Event Response class member function typedef void (ccobject::* sel_ EventHandler) (ccevent*);//define some macros to obtain pointers to these callback member functions. #define Schedule_selector (_selector) (Sel_schedule) (&_selector) #define Callfunc_selector (_selector) (SEL_ Callfunc) (&_selector) #define Callfuncn_selector (_selector) (SEL_CALLFUNCN) (&_selector) #define CallfuncND_ SelectoR (_selector) (SEL_CALLFUNCND) (&_selector) #define Callfunco_selector (_selector) (Sel_callfunco) (&_SELECTOR ) #define Menu_selector (_selector) (Sel_menuhandler) (&_selector) #define Event_selector (_selector) (sel_ EventHandler) (&_selector) #define Compare_selector (_selector) (Sel_compare) (&_selector) Nc_cc_end#endif//_ _ccobject_h_
CCObject.cpp:
#include "CCObject.h"//Memory Manager header file # include "CCAutoreleasePool.h"//cocos2d-x some macros defined in the header file # include "CcMacros.h"//Join Script Support # Include "scripte_support/ccscriptsupport.h" ns_cc_begin//virtual function. Here's a simple deal.    You need to overload ccobject* Cccopying::copywithzone (Cczone *pzone) {cc_unused_param (Pzone);//If you do not overload, you will be prompted not to overload the implementation functions.    Ccassert (0, "not implement"); return 0;} Construct Ccobject::ccobject (void) {///define a static UINT type variable as an instance object counter, this value will only grow, will not be reduced, guaranteed to be unique. static unsigned int uobjectcount = 0;//assigns a value to a unique ID after adding 1 to the counter. Note: All subclasses derived from this Ccobject class will also have this unique ID. It allows us to get the corresponding instance object through a unique ID. M_uid = ++uobjectcount;//Script id m_nluaid = 0;//when the class is instantiated, M_ureference is set to 1m_ureference = 1;//is initialized when the instantiated object is managed by the user for memory management. If new is an object, you need to delete it yourself. m_bmanaged = false;} destructor Ccobject::~ccobject (void) {if memory is managed uniformly by the memory manager, the Remove function that invokes the memory manager instance object is freed from its own memory.    if (m_bmanaged) {ccpoolmanager::getinstance ()->removeobject (this);}    If a LUA script is used, the Remove function that invokes the instance object of the scripting engine removes itself from the instance object of the scripting engine.    if (m_nluaid) {Ccscriptenginemanager::sharedmanager ()->getscriptengine ()->removeccobjectbyid (M_nLuaID); }}//returns an instantiated object of this classCopy of ccobject* Ccobject::copy () {return copywithzone (0);} Release function for external call of the consumer void Ccobject::release (void) {//First make sure that the counter is a numeric value greater than 0, stating that it is valid Ccassert (m_ureference > 0, "Reference count Should greater than 0 ");//Counter minus 1--m_ureference;//if the counter is reduced to 0, the memory used by this class instantiation object is freed if (m_ureference = = 0) {delete this;}} Called by the consumer, the counter is updated when used once. void Ccobject::retain (void) {Ccassert (m_ureference > 0, "Reference count should greater than 0"); ++m_ureference;} Sets the memory management of the instantiated object of the current class to the memory manager to manage, without manual memory counter processing. ccobject* ccobject::autorelease (void) {//calls the AddObject function of the memory manager instance object to join the pointer to the current Ccobject instance Object Ccpoolmanager::getinstance ()- >addobject (this);//Open the tag using memory manager m_bmanaged = True;return this;} Whether the instantiated object of the current class is used only by one consumer, the number of bool Ccobject::issinglerefrence (void) {///counters represents the number of users, because one user uses the counter plus 1return m_ Ureference = = 1;} Returns the number of users of the instantiated object of the current class unsigned int ccobject::retaincount (void) {return m_ureference;} Whether the instantiated object with another base class of Ccobject is the same object bool Ccobject::isequal (const Ccobject *pobject) {return this = = Pobject;}  Ns_cc_end

Ccobject, as the parent class of most classes in COCOS2DX, provides memory management functions, provides object ID management for scripts, and serializes interfaces;

Ccnode

Node class Ccnode can be said to be the ancestor of the game elements , basically we see the game elements are based on it as a prototype extension. Like ccscene,cclayer,ccsprite,ccmenu , Ccspritebatchnode and so on, all from Ccnode to inherit. In addition, if we want to customize the sprite, then inherit from Ccnode is also a very good choice. Ccnodedirectly fromCcobjectinherited from, has the following several characteristics:

    • can contain other Ccnode node that can be added / Get / Deletes a child node operation.
    • A recurring callback task can be performed.
    • can perform actions.

some sub-typed nodes provide richer features and functionality.

Property
Features of Ccnode:-position                                   //position, default (0,0)-scale (x, y)                               //Zoom, default (All)-rotation (in degrees, clockwise)           //Spin Turn, default is 0-skew                                       //Tilt, default is 0-cccamera (an interface to Glulookat)      //cccamera, viewpoint conversion, each node has, default point to Node Center-ccgridbase (to D o mesh Transformations)    //ccgridbase, NET class transition-anchor                               point//Anchor, default (0,0)-size                                       //Dimension, default (0,0)-Visible                                    // Visible-Z-order                                    //z axis value-OpenGL z position                          //opengl Z-value
Initialization
Initializes the function that successfully returns TRUE for    virtual BOOL init ();//Allocates memory space, calls Init and adds autorelease tag    static Ccnode * Create (void);        Returns a description string    const char* description (void);
Graphic properties
    Set/Get z-axis order, z-axis large overlay z-axis small virtual void setzorder (int zOrder);    virtual void _setzorder (int z);    virtual int getzorder ();    Set/Get OpenGL Z-axis vertex virtual void Setvertexz (float vertexz);    Virtual float getvertexz ();    Set/Get Zoom value virtual void Setscalex (float fscalex);    Virtual float Getscalex ();    virtual void Setscaley (float Fscaley);    Virtual float Getscaley ();    virtual void Setscale (float scale);    Virtual float getscale ();    virtual void Setscale (float fscalex,float Fscaley);    Set/Get location virtual void setposition (const ccpoint &position);    Virtual const ccpoint& getPosition ();    virtual void SetPosition (float x, float y);    virtual void GetPosition (float* x, float* y);    virtual void Setpositionx (float x);    Virtual float Getpositionx (void);    virtual void Setpositiony (float y);        Virtual float getpositiony (void);    Set/get tilt angle virtual void setskewx (float fskewx);    Virtual float getskewx (); virtual void Setskewy (float fskewy);   Virtual float getskewy ();    Set/get Anchor point virtual void setanchorpoint (const ccpoint& anchorpoint);    Virtual const ccpoint& Getanchorpoint ();        Virtual const ccpoint& getanchorpointinpoints ();    Set/Get size virtual void setcontentsize (const ccsize& contentsize);    Virtual const ccsize& getcontentsize () const;    Set/get visibility of virtual void setvisible (bool visible);    virtual bool isVisible ();    Set/get rotation angle virtual void setrotation (float frotation);    Virtual float getrotation ();    virtual void Setrotationx (float frotaionx);    Virtual float Getrotationx ();    virtual void Setrotationy (float frotationy); Virtual float getrotationy ();
Node operations
Add/Get child nodes, can have z-axis order (default is 0) and label virtual void AddChild (Ccnode *);    virtual void AddChild (Ccnode * child, int zOrder);    virtual void AddChild (ccnode* child, int zOrder, int tag);    Ccnode * Getchildbytag (int tag);    Virtual ccarray* getChildren ();        unsigned int getchildrencount (void) const;    Set/Get parent node virtual void setParent (ccnode* parent);        Virtual ccnode* getParent ();    Removes itself from the parent node, the default cleanup is true virtual void removefromparent ();    virtual void Removefromparentandcleanup (bool cleanup);    Removing child nodes virtual void removechild (ccnode*);    virtual void RemoveChild (ccnode* child, bool cleanup);    virtual void Removechildbytag (int tag);    virtual void Removechildbytag (int tag, bool cleanup);    Remove all nodes virtual void removeallchildren ();        virtual void Removeallchildrenwithcleanup (bool cleanup); Reset node order virtual void Reorderchild (Ccnode * child, int zOrder);
tags and user data
    Set/Get tag    virtual int gettag () const;    virtual void Settag (int nTag);        Set/Get UserData, which is a pointer to any block of data you want, but remember to release    virtual void* getuserdata ();    virtual void Setuserdata (void *puserdata);        Set/Get Ccobject, as above, just data replaced with Ccobject object    virtual ccobject* getuserobject ();    virtual void Setuserobject (Ccobject *puserobject);
Event callbacks
    Event callback        //node starts to enter the trigger    virtual void onEnter ();    Node completion enters trigger    virtual void onentertransitiondidfinish ();    Node exit triggers    virtual void onExit ();    If the node exits with a transition animation, the animation starts with    virtual void Onexittransitiondidstart ();    Stop animation and scheduler    virtual void cleanup (void);
Action
    Get/Set Action Manager    virtual void Setactionmanager (ccactionmanager* actionmanager);    Virtual ccactionmanager* getactionmanager ();        Run Action    ccaction* runaction (ccaction* action);    Stop action    void stopallactions (void);    void Stopaction (ccaction* action);    void Stopactionbytag (int tag);    ccaction* getactionbytag (int tag);    Gets the number of running actions    unsigned int numberofrunningactions (void);
Scheduler and Timers
   Get/Set Scheduler    virtual void Setscheduler (ccscheduler* scheduler);    Virtual ccscheduler* getscheduler ();        Detects if a scheduler is running    bool isscheduled (sel_schedule selector);    Open update schedule    void scheduleupdate (void);    Set the scheduling priority    void scheduleupdatewithpriority (int priorities);    Close the update scheduler    void unscheduleupdate (void);    Open/close/Resume/pause Scheduler    void Schedule (sel_schedule selector, float interval, unsigned int repeat, float delay);    void Schedule (Sel_schedule selector, float interval);    void Scheduleonce (sel_schedule selector, float delay);    void Schedule (Sel_schedule selector);    void Unschedule (sel_schedule selector);    void unscheduleallselectors (void);    void resumeschedulerandactions (void);    void pauseschedulerandactions (void);        Call function per frame    virtual void update (float delta);
Coordinate transformation
    Coordinate transformation related, this part is introduced later    Ccpoint converttonodespace (const ccpoint& worldpoint);    Ccpoint converttoworldspace (const ccpoint& nodepoint);    Ccpoint converttonodespacear (const ccpoint& worldpoint);    Ccpoint converttoworldspacear (const ccpoint& nodepoint);    Ccpoint converttouchtonodespace (Cctouch * touch);    Ccpoint converttouchtonodespacear (Cctouch * touch);
Other
    Get/Set Coloring program    virtual ccglprogram* getshaderprogram ();    virtual void Setshaderprogram (Ccglprogram *pshaderprogram);        Get Cccamera Object    virtual cccamera* getcamera ();        Whether the node is running    virtual bool isrunning ();    Draw node    virtual void draw (void);    Recursive access node    virtual void visit (void);    Returns the occupied rectangle, the node coordinate system    Ccrect boundingbox (void);

[COCOS2DX]COCOS2DX Main class

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.