溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

[Cocos2d-x]視差滾屏效果的實現(xiàn)

發(fā)布時間:2020-07-24 13:27:15 來源:網(wǎng)絡(luò) 閱讀:273 作者:蓬萊仙羽 欄目:游戲開發(fā)

視差滾屏效果的實現(xiàn):

我們在做IOS游戲開發(fā)的時候,經(jīng)常會遇到那種屏幕動的效果,比如跑酷類的游戲,就這這種效果的典型應(yīng)用。

效果圖:

[Cocos2d-x]視差滾屏效果的實現(xiàn)

核心代碼:

bool HelloWorld::init() {     //////////////////////////////     // 1. super init first     if ( !CCLayer::init() )     {         return false;     }      CCSize screenSize = CCDirector::sharedDirector()->getWinSize();     CCSprite *para1 = CCSprite::create("parallax1.png");     CCSprite *para2 = CCSprite::create("parallax2.png");     CCSprite *para3 = CCSprite::create("parallax3.png");     CCSprite *para4 = CCSprite::create("parallax4.png");     para1->setAnchorPoint(CCPointMake(0, 1));     para2->setAnchorPoint(CCPointMake(0, 1));     para3->setAnchorPoint(CCPointMake(0, 0.6f));     para4->setAnchorPoint(CCPointMake(0, 0));     CCPoint topOffset = CCPointMake(0, screenSize.height);     CCPoint midOffset = CCPointMake(0, screenSize.height/2);     CCPoint downOffset = CCPointMake(0, 0);     CCParallaxNode* paraNode = CCParallaxNode::create();     paraNode->addChild(para1, 1, CCPointMake(0, 10), topOffset);     paraNode->addChild(para2, 2, CCPointMake(0, 10), topOffset);     paraNode->addChild(para3, 3, CCPointMake(0, 10), midOffset);     paraNode->addChild(para4, 4, CCPointMake(0, 10), downOffset);     this->addChild(paraNode,2,1);          CCMoveBy*move1 = CCMoveBy::create(3, CCPointMake(0, -160));     CCMoveBy*move2 = CCMoveBy::create(3, CCPointMake(0, 160));     CCSequence*sequence = CCSequence::create(move1,move2,NULL);     CCRepeatForever *repeat = CCRepeatForever::create(sequence);     paraNode->runAction(repeat);          return true; }


資源下載[猛戳]

原碼:http://download.csdn.net/detail/s10141303/6239585

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI