CCComponentContainer,CCComponent解析

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值