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

视差滚屏效果的实现:

我们在做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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值