cocos2dx 3.1.1官方demo阅读-ActionsProgressTest【进度条】

来源:互联网 发布:七夕表白源码 编辑:程序博客网 时间:2024/05/01 13:50

1,SpriteProgressToRadial(旋转进度条)

    auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));    auto left = ProgressTimer::create(Sprite::create(s_pathSister1));//设置进度条的类型    left->setType( ProgressTimer::Type::RADIAL );    addChild(left);    left->setPosition(Vec2(100, s.height/2));    left->runAction( RepeatForever::create(to1));


2,SpriteProgressToHorizontal(水平进度条)

    auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));    auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));        auto left = ProgressTimer::create(Sprite::create(s_pathSister1));    left->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the left since the midpoint is 0 for the x//设置midpoint的x为0,表示进度条从坐标开始,要从右开始,设置为1。    left->setMidpoint(Vec2(0,0));    //    Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change//设置change rate的y为0,表示y方向上不存在变化,而x设置为1,所以就是一个水平的进度条    left->setBarChangeRate(Vec2(1, 0));    addChild(left);    left->setPosition(Vec2(100, s.height/2));    left->runAction( RepeatForever::create(to1));


3,SpriteProgressToVertical(垂直进度条)


    auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));    auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));        auto left = ProgressTimer::create(Sprite::create(s_pathSister1));    left->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y//设置midPoint的y为0,所以起点从底部开始    left->setMidpoint(Vec2(0,0));    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change//同上,change rate x设置成0,表示在x方向上没有变化,也就是垂直进度条    left->setBarChangeRate(Vec2(0, 1));    addChild(left);    left->setPosition(Vec2(100, s.height/2));    left->runAction( RepeatForever::create(to1));

4,SpriteProgressToRadialMidpointChanged(中心点改变的旋转进度条)

 auto s = Director::getInstance()->getWinSize();    auto action = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));    /**   *  Our image on the left should be a radial progress indicator, clockwise   */    auto left = ProgressTimer::create(Sprite::create(s_pathBlock));    left->setType(ProgressTimer::Type::RADIAL);    addChild(left);//设置旋转的中心点    left->setMidpoint(Vec2(0.25f, 0.75f));    left->setPosition(Vec2(100, s.height/2));    left->runAction(RepeatForever::create(action->clone()));

5,SpriteProgressBarVarious(midPoint和changrate不同参数的情况)

auto to = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));    auto left = ProgressTimer::create(Sprite::create(s_pathSister1));    left->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y//设置起点是(0.5,0.5)    left->setMidpoint(Vec2(0.5f, 0.5f));    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change//只在x方向上有改变    left->setBarChangeRate(Vec2(1, 0));    addChild(left);    left->setPosition(Vec2(100, s.height/2));    left->runAction(RepeatForever::create(to->clone()));    auto middle = ProgressTimer::create(Sprite::create(s_pathSister2));    middle->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y    middle->setMidpoint(Vec2(0.5f, 0.5f));    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change//x,y上都有改变    middle->setBarChangeRate(Vec2(1,1));    addChild(middle);    middle->setPosition(Vec2(s.width/2, s.height/2));    middle->runAction(RepeatForever::create(to->clone()));    auto right = ProgressTimer::create(Sprite::create(s_pathSister2));    right->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y    right->setMidpoint(Vec2(0.5f, 0.5f));    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change//只在y上有改变    right->setBarChangeRate(Vec2(0, 1));    addChild(right);    right->setPosition(Vec2(s.width-100, s.height/2));    right->runAction(RepeatForever::create(to->clone()));

6,SpriteProgressBarTintAndFade(带tint和fade效果的进度条)

    auto tint = Sequence::create(TintTo::create(1, 255, 0, 0),                                   TintTo::create(1, 0, 255, 0),                                   TintTo::create(1, 0, 0, 255),                                   NULL);    auto fade = Sequence::create(FadeTo::create(1.0f, 0),                                   FadeTo::create(1.0f, 255),                                   NULL);    auto right = ProgressTimer::create(Sprite::create(s_pathSister2));    right->setType(ProgressTimer::Type::BAR);    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y    right->setMidpoint(Vec2(0.5f, 0.5f));    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change    right->setBarChangeRate(Vec2(0, 1));    addChild(right);    right->setPosition(Vec2(s.width-100, s.height/2));    right->runAction(RepeatForever::create(to->clone()));right->runAction(RepeatForever::create(tint->clone()));    right->runAction(RepeatForever::create(fade->clone()));

7,SpriteProgressWithSpriteFrame

唯一不同的就是可以用精灵框帧。

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");    auto left = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png"));


 

0 0