您的位置:首页 > 大数据 > 人工智能

CCComponentContainer,CCComponent解析

2015-08-26 23:27 701 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: