#ifndef __CC_FRAMEWORK_COMPONENT_H__
#define __CC_FRAMEWORK_COMPONENT_H__
#include "cocoa/CCObject.h"
#include <string>
NS_CC_BEGIN
class CC_DLL CCComponent : public CCObject // Component 组件 成分
{
protected:
CCComponent(void);
public:
virtual ~CCComponent(void);
virtual bool init();
virtual void onEnter();
virtual void onExit();
virtual void update(float delta);
virtual void serialize(void* r);//使连续
virtual bool isEnabled() const;
virtual void setEnabled(bool b);
static CCComponent* create(void);
const char* getName() const;
//设置 得到拥有者
void setOwner(CCNode *pOwner);
CCNode* getOwner() const;
protected:
CCNode *m_pOwner;
std::string m_strName;
bool m_bEnabled;
};
NS_CC_END
#endif // __FUNDATION__CCCOMPONENT_H__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "support/component/CCComponent.h"
NS_CC_BEGIN
CCComponent::CCComponent(void)
: m_pOwner(NULL)
, m_bEnabled(true)
{
}
CCComponent::~CCComponent(void)
{
}
bool CCComponent::init()
{
return true;
}
void CCComponent::onEnter()
{
}
void CCComponent::onExit()
{
}
void CCComponent::update(float delta)
{
}
void CCComponent::serialize(void *ar)
{
}
CCComponent* CCComponent::create(void)
{
CCComponent * pRet = new CCComponent();
if (pRet != NULL && pRet->init())
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
const char* CCComponent::getName() const
{
return m_strName.c_str();
}
CCNode* CCComponent::getOwner() const
{
return m_pOwner;
}
void CCComponent::setOwner(CCNode *pOwner)
{
m_pOwner = pOwner;
}
bool CCComponent::isEnabled() const
{
return m_bEnabled;
}
void CCComponent::setEnabled(bool b)
{
m_bEnabled = b;
}