从Delphi开始学Cocos2dx-3.0[3]:CCNode 可视组件的头

本文深入解析了Cocos引擎中的CCNode类,包括其核心属性如位置、缩放、旋转等,以及与节点相关的函数如添加、删除、排序等。详细介绍了如何通过CCNode类进行节点的管理和属性调整,适用于Cocos开发者深入理解引擎底层逻辑。

几乎Cocos中所有能看得到的类, 都是从 CCNode 继承下来的. 如同Delphi中的 TControl


CCNode 类的属性
属性描述默认值
virtual const Point& getPosition() const;位置 
virtual float getScale() const;缩放 
virtual float getRotation() const;旋转 
virtual Camera* getCamera();摄像机 
virtual const GridBase* getGrid() const { return _grid; }网格 
virtual const Size& getContentSize() const;尺寸 
virtual bool isVisible() const;可见 
virtual void setZOrder(int zOrder);Z坐标 
   
   

 Default values:
 - rotation: 0
 - position: (x=0,y=0)
 - scale: (x=1,y=1)
 - contentSize: (x=0,y=0)
 - anchorPoint: (x=0,y=0)




CCNode 和节点有关的函数

 /** 
     * 将对象添加到节点,默认Z坐标为0
     *
     * 如果孩子被添加到“running”节点,然后onenter”和“onentertransitiondidfinish”会被立刻回调。
     *
     * @param child A child node
     */
    virtual void addChild(Node * child);
    /** 
     * 将对象添加到节点,指定Z坐标
     *
     * 如果孩子被添加到“running”节点,然后onenter”和“onentertransitiondidfinish”会被立刻回调。
     *
     * @param child     A child node
     * @param zOrder    Z order for drawing priority. Please refer to setZOrder(int)
     */
    virtual void addChild(Node * child, int zOrder);
    /** 
     * 将对象添加到节点,指定Z坐标和标志值
     *
     * 如果孩子被添加到“running”节点,然后onenter”和“onentertransitiondidfinish”会被立刻回调。
     *
     * @param child     A child node
     * @param zOrder    Z order for drawing priority. Please refer to setZOrder(int)
     * @param tag       A interger to identify the node easily. Please refer to setTag(int)
     */
    virtual void addChild(Node* child, int zOrder, int tag);
    /**
     * 获取标志值所表示的子节点
     *
     * @param tag   An identifier to find the child node.
     *
     * @return a Node object whose tag equals to the input parameter
     */
    Node * getChildByTag(int tag);
    /**
     * 返回所有子节点的数组
     *
     * Composing a "tree" structure is a very important feature of Node
     * Here's a sample code of traversing children array:
     * @code
     * Node* node = NULL;
     * CCARRAY_FOREACH(parent->getChildren(), node)
     * {
     *     node->setPosition(0,0);
     * }
     * @endcode
     * This sample code traverses all children nodes, and set there position to (0,0)
     *
     * @return An array of children
     */
    virtual Array* getChildren() { return _children; }
    virtual const Array *getChildren() const { return _children; }
    
    /** 
     * 获得子节点的数量
     *
     * @return The amount of children.
     */
    unsigned int getChildrenCount() const;
    
    /**
     * 设置父节点
     *
     * @param parent    A pointer to the parnet node
     */
    virtual void setParent(Node* parent);
    /**
     * 返回父节点(爸爸去哪儿, 爸爸只有一个, 没有爸爸们)
     * 
     * @see setParent(Node*)
     *
     * @returns A pointer to the parnet node
     */
    virtual Node* getParent() { return _parent; }
    virtual const Node* getParent() const { return _parent; }

    
    ////// REMOVES //////
    
    /** 
     * 从父节点移除,并且清除
     * If the node orphan, then nothing happens.
     * @see removeFromParentAndCleanup(bool)
     */
    virtual void removeFromParent();
    /** 
     * 从父节点移除,并不一定清除
     * If the node orphan, then nothing happens.
     * @param cleanup   true if all actions and callbacks on this node should be removed, false otherwise.
     * @js removeFromParent
     * @lua removeFromParent
     */
    virtual void removeFromParentAndCleanup(bool cleanup);

    /** 
     * 通过对象指针移除子节点并清除
     * 
     * @param child     The child node which will be removed.
     * @param cleanup   true if all running actions and callbacks on the child node will be cleanup, false otherwise.
     */
    virtual void removeChild(Node* child, bool cleanup = true);

    /** 
     * 通过标志值移除子节点并清除
     * 
     * @param tag       An interger number that identifies a child node
     * @param cleanup   true if all running actions and callbacks on the child node will be cleanup, false otherwise. 
     */
    virtual void removeChildByTag(int tag, bool cleanup = true);
    /** 
     * AOE!! 子节点全清除
     *
     * @see removeAllChildrenWithCleanup(bool)
     */
    virtual void removeAllChildren();
    /** 
     * AOE!! 子节点全移除,但不一定清除
     *
     * @param cleanup   true if all running actions on all children nodes should be cleanup, false oterwise.
     * @js removeAllChildren
     * @lua removeAllChildren
     */
    virtual void removeAllChildrenWithCleanup(bool cleanup);
    
    /** 
     * 重新设置子节点的Z坐标
     *
     * @param child     An already added child node. It MUST be already added.
     * @param zOrder    Z order for drawing priority. Please refer to setZOrder(int)
     */
    virtual void reorderChild(Node * child, int zOrder);
    
    /** 
     * 通过排序所有子节点,提供渲染性能.  慎用!
     * This appraoch can improves the performance massively.
     * @note Don't call this manually unless a child added needs to be removed in the same frame 
     */
    virtual void sortAllChildren();

    /// @} end of Children and Parent
    

    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值