温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

[Cocos2d-x]视差滚屏效果的实现

发布时间:2020-07-24 13:27:15 来源:网络 阅读:274 作者:蓬莱仙羽 栏目:游戏开发

视差滚屏效果的实现:

我们在做IOS游戏开发的时候,经常会遇到那种屏幕动的效果,比如跑酷类的游戏,就这这种效果的典型应用。

效果图:

[Cocos2d-x]视差滚屏效果的实现

核心代码:

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问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI