CCComponentContainer,CCComponent解析

来源:互联网 发布:微商城与淘宝的区别 编辑:程序博客网 时间:2024/05/22 12:23

CCComponent:


源码:

enum {    kComponentOnEnter,    kComponentOnExit,    kComponentOnUpdate};/// 组件class CC_DLL Component : public Ref{CC_CONSTRUCTOR_ACCESS:    /**     * @js ctor     */    Component(void);public:    /**     * @js NA     * @lua NA     */    virtual ~Component(void);    virtual bool init();/// 进入的时候调用    virtual void onEnter();/// 退出的时候调用    virtual void onExit();/// 更新    virtual void update(float delta);/// 是否序列化    virtual bool serialize(void* r);/// 是否可用    virtual bool isEnabled() const;/// 设置状态    virtual void setEnabled(bool b);/// 创建一个组件    static Component* create(void);    /// 得到名字    const std::string& getName() const;/// 设置名字    void setName(const std::string& name);    /// 设置拥有者    void setOwner(Node *pOwner);/// 得到拥有者    Node* getOwner() const;protected:    Node *_owner;    std::string _name;    bool _enabled;    #if CC_ENABLE_SCRIPT_BINDING    ccScriptType _scriptType;         ///< type of script binding, lua or javascript#endif};

CCComponentContainer:


源码:

/// 组件容器class CC_DLL ComponentContainer{protected:    /**     * @js ctor     */ /// 构造    ComponentContainer(Node *pNode);    public:    /**     * @js NA     * @lua NA     */ /// 析构    virtual ~ComponentContainer(void);/**     * @js getComponent     */ /// 得到组件virtual Component* get(const std::string& name) const;/// 添加组件    virtual bool add(Component *com);/// 移除组件    virtual bool remove(const std::string& name);/// 移除组件    virtual bool remove(Component *com);/// 移除所有组件    virtual void removeAll();/// 访问,更新所有的组件    virtual void visit(float delta);public:/// 是否是空的    bool isEmpty() const;    private:/// 分配,新建的一个存储组件的Map    void alloc(void);    private:    Map<std::string, Component*>* _components;    Node *_owner;        friend class Node;};NS_CC_END


0 0