1. Add two genie to the Layer
CCSprite * pSp1 = CCSprite: create ("bg01.jpg ");
CCSprite * pSp2 = CCSprite: create ("bg01.jpg ");
PSp1-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width/2, CCDirector: shareddire()-> getWinSize (). height/2 ));
PSp2-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width/2, CCDirector: shareddire()-> getWinSize (). height/2 + 576); // The height of the background image is 576.
This-> addChild (pSp1, 0, 11 );
This-> addChild (pSp2, 0, 12 );
2. Start the screen rolling timer.
This-> schedule (schedule_selector (GamingLayer: BackgroundScrollLogic), 0.1f );
3. Implementation of the scrolling callback function
Void GamingLayer: BackgroundScrollLogic (float t)
{
CCSprite * pBg1 = (CCSprite *) getChildByTag (11 );
CCSprite * pBg2 = (CCSprite *) getChildByTag (12 );
PBg1-> setPositionY (pBg1-> getPositionY ()-10); // move 10 pixels each time
PBg2-> setPositionY (pBg1-> getPositionY () + 576); // Step 2
// If the second image is rolled to the end, reset the original position of genie 1.
If (pBg2-> getPositionY () <= CCDirector: shareddire()-> getWinSize (). height/2)
{
PBg1-> setPositionY (CCDirector: shareddire()-> getWinSize (). height/2 );
}
}