[Cocos2d-x]视差滚屏效果的实现
2013-09-09 21:10
323 查看
视差滚屏效果的实现:
我们在做IOS游戏开发的时候,经常会遇到那种屏幕动的效果,比如跑酷类的游戏,就这这种效果的典型应用。效果图:
核心代码:
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
相关文章推荐
- [Cocos2d-x]视差滚屏效果的实现
- cocos2d-x-3.0学习笔记之使用listView实现滚屏效果
- 【Cocos2d-x游戏引擎开发笔记(17)】实现运动的尾巴效果
- Cocos2d-x实现粒子效果的三种方式
- Cocos2d-js中实现惯性滑动效果
- Cocos2d-x能够实现的效果总结
- 【Cocos2D-X 游戏引擎】初窥门径(15)实现拖尾效果
- ViewPager+Fragment+PageTransformer实现3D、视差等多种动画效果(雷惊风)
- Cocos2d-x实现android的Toast效果
- 使用UITableView实现图片视差效果
- javascript实现页面滚屏效果_优就业
- 推荐六款帮助你实现惊艳视差滚动效果的 jQuery 插件
- Cocos2d-x能够实现的效果总结
- cocos2d-x 基于CCClippingNode实现CCLayer遮罩功能,在滑动时超出剪切区域的实现显示部分的效果,不需要再借助其他sprite来遮挡了
- 怎么在cocos2d与GLSL2.0中用shader实现很酷的效果
- Cocos2d-js中实现惯性滑动效果
- Android头部视差效果的实现方式
- Cocos2d-x 实现技能冷却效果
- cocos2d实现CCLabelTTF真正字体描边效果
- cocos2d-x3.1 下实现类似Android下ExpandListView的效果