状态模式

状态模式:允许对象在内部状态改变时改变它的行为,对像看起来好像修改了它的类。


查看源代码可知,cocos2d也使用了状态模式,

class CC_DLL CCDirector : public CCObject, public TypeInfo{

   /* The running scene */

   CCScene *m_pRunningScene;


   /* will be the next 'runningScene' in the next frame

    nextScene is a weak reference. */

   CCScene *m_pNextScene;

   void runWithScene(CCScene *pScene);

   void replaceScene(CCScene *pScene);

CCScene 就代表了状态。

你可能感兴趣的:(cocos2d,状态模式)