cocos2d-x过程动作CCProgressTo示例学习笔记

时间:2021-11-21 23:27:54
//
// SpriteProgressToRadial
//
//------------------------------------------------------------------
void SpriteProgressToRadial::onEnter()
{
    SpriteDemo::onEnter();
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCProgressTo *to1 = CCProgressTo::create(2, 100);//动作时间,显示百分比
    CCProgressTo *to2 = CCProgressTo::create(2, 100);

    CCProgressTimer *left = CCProgressTimer::create(CCSprite::create(s_pPathSister1));//传人精灵对象
    
    //kCCProgressTimerTypeBar为进度条的形式,cocos2d-x封装了2种显示方式:条形:kCCProgressTimerTypeBar,圆弧形:kCCProgressTimerTypeRadial
    left->setType( kCCProgressTimerTypeBar );//设置动画类型
    
    addChild(left);
    left->setPosition(ccp(100, s.height/2));
    left->setMidpoint(ccp(0.25f, 0.75f));//设置开始展示点的位置,动画开始的起始点
    left->runAction( CCRepeatForever::create(to1));
    
    CCProgressTimer *right = CCProgressTimer::create(CCSprite::create(s_pPathBlock));
    right->setType(kCCProgressTimerTypeRadial);
    // Makes the ridial CCW
    right->setReverseProgress(true);//逆时针方向展开
    addChild(right);
    right->setPosition(ccp(s.width-100, s.height/2));
    right->runAction( CCRepeatForever::create(to2));
}

//另外,当类型为直线扫描的动画(条形)时,
right->setMidpoint(ccp(x, y)); //设置动画开始点x轴,y轴的起始坐标(百分百),
//示例:
        right->setMidpoint(ccp(1,0));  // 动画从右下角开始向其它地方扩展
        right->setMidpoint(ccp(0, 1));   //动画从左上角开始向其它地方扩展
left->setBarChangeRate(ccp(x,y))  //设置动画完成后,x轴、y轴最终改变的比例(百分比),
//示例:
       left->setBarChangeRate(ccp(0.5,0)); // 此例开始时x显示一半,y轴显示全部,最终,x轴改变0.5,y轴改变0

//这两个函数结合:
left->setType(kCCProgressTimerTypeBar);
left->setMidpoint(ccp(0,0));
left->setBarChangeRate(ccp(1,0));     // 效果为整张动画从最左边的边界开始,向右边界推进,直到最终完全显示


欢迎转载,转载请注明出处: http://blog.csdn.net/somestill/article/details/9406501