title: Moving between "pages" ( CCLayer ) in cocos2dx
body: <p>I have 2 MyGameScreen objects that extends cocos2d::CCLayer. I am capturing the ccTouchesMove of the first screen so that I can create the moving effect exactly like sliding between pages of iOS application screen.</p>
  
  <p>My class is like so:</p>
  
  <pre><code>class MyGameScreen: public cocos2d::CCLayer {
      cocos2d::CCLayer* m_pNextScreen;
  }
  
  bool MyGameScreen::init() {
      m_pNextScreen = MyOtherScreen::create();
  }
  
  void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event){
      // it crashes here... on the setPosition... m_pNextScreen is valid pointer though I am not sure that MyOtherScreen::create() is all I need to do...
      m_pNextScreen-&gt;setPosition( CCPointMake( (fMoveTo - (2*fScreenHalfWidth)), 0.0f ) );
  }
  </code></pre>
  
  <p>EDIT: adding clear question</p>
  
  <p>It crashed when I try to setPosition on m_pNextScreen...</p>
  
  <p>I have no idea why it crashed as m_pNextScreen is a valid pointer and is properly initialized. Could anybody explain why?</p>
  
  <p>EDIT: adding progress report</p>
  
  <p>I remodelled the whole system and make a <code>class CContainerLayer : public cocos2d::CCLayer</code> that contains both <code>MyGameScreen</code> and <code>MyOtherScreen</code> side by side. However, this looked like not an efficient approach, as when it grows I may need to have more than 2 pages scrollable side by side, I'd prefer to load the next page only when it is needed rather than the entire <code>CContainerLayer</code> that contains all the upcoming pages whether the user will scroll there or not... Do you have any better idea or github open source sample that does this?</p>
  
  <p>Thank you very much for your input!</p>