// 创建cat精灵 CCSprite* cat = CCSprite::create("Image\grossini.png"); //change the transform anchor point to 0,0 (optional) cat->setAnchorPoint( ccp(0,0) ); //创建 background 精灵最为背景 CCSprite* background = CCSprite::create("Image\background.png"); // scale the image (optional) background->setScale( 2.0f ); // change the transform anchor point (optional) background->setAnchorPoint( ccp(0,0) ); // 创建一个parallax节点用于储存各种精灵,然后移动parallax节点以展示“视差”效果 CCParallaxNode* voidNode = CCParallaxNode::create(); // background的移动速度为 0.4x, 0.5y voidNode->addChild(background, -1, ccp(0.4f,0.5f), CCPointZero); // cat的移动速度为 3.0x, 2.5y voidNode->addChild(cat, 1, ccp(3.0f,2.5f), ccp(200,800) ); //移动 CCParallaxNode 产生视差效果 CCActionInterval* goUp = CCMoveBy::create(4, ccp(0,-500) ); CCActionInterval* goDown = goUp->reverse(); CCActionInterval* go = CCMoveBy::create(8, ccp(-1000,0) ); CCActionInterval* goBack = go->reverse(); CCFiniteTimeAction* seq = CCSequence::create(goUp, go, goDown, goBack, NULL); voidNode->runAction( (CCRepeatForever::create((CCActionInterval*) seq) )); addChild( voidNode );