Cocos2d-x 3.4
进度条
旋转进度条
auto s =
Director::getInstance()->getWinSize();
auto to1 =
Sequence::createWithTwoActions(ProgressTo::create(2,100),ProgressTo::create(0,0));//旋转进度条
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::RADIAL);
left->setReverseProgress(true);//反转执行
addChild(left);
left->setPosition(100,s.height/2);
left->runAction(RepeatForever::create(to1));
水平进度条
auto to2 =
Sequence::createWithTwoActions(ProgressTo::create(2,100),ProgressTo::create(0,0));
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::BAR);//BAR
水平进度条
left->setMidpoint(Vec2(1,0));//从右到左
,Vec2(0,0)为从左到右
left->setBarChangeRate(Vec2(1,0));
addChild(left);
left->setPosition(100,s.height/2);
left->runAction(RepeatForever::create(to2));
垂直进度条
auto t3 =
Sequence::createWithTwoActions(ProgressTo::create(2,100),ProgressTo::create(0,0));
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::BAR);
left->setMidpoint(Vec2(0,1));//从上到下,Vec2(0,0)为从下到上
left->setBarChangeRate(Vec2(0,1));
addChild(left);
left->setPosition(100,s.height/2);
left->runAction(RepeatForever::create(t3));
BAR类型进度条设置变化
auto t5 =
Sequence::createWithTwoActions(ProgressTo::create(2,100),ProgressTo::create(0,0));
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::BAR);
left->setMidpoint(Vec2(0.5f,0.5f));
left->setBarChangeRate(Vec2(1,1));//从中心向四周扩散,Vec2(1,0)从中心向两边扩散,Vec2(0,1)从中心向山下扩散
addChild(left);
left->setPosition(s.width/2,s.height/2);
left->runAction(RepeatForever::create(t5));
可变换旋转中心的旋转进度条
auto t4 =
Sequence::createWithTwoActions(ProgressTo::create(2,100),ProgressTo::create(0,0));
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::RADIAL);
left->setMidpoint(Vec2(0.75f,0.25f));//设置旋转中心点
left->setBarChangeRate(Vec2(0,1));
addChild(left);
left->setPosition(100,s.height/2);
left->runAction(RepeatForever::create(t4));
进度条搭配其他动作
auto t6 =
Sequence::createWithTwoActions(ProgressTo::create(6,100),ProgressTo::create(0,0));
auto hint =
Sequence::create(TintTo::create(1,255,0,0),TintTo::create(1,0,255,0),TintTo::create(1,0,0,255),nullptr);
auto left =
ProgressTimer::create(Sprite::create("Images/grossini.png"));
left->setType(ProgressTimer::Type::BAR);
left->setMidpoint(Vec2(0.5f,0.5f));
left->setBarChangeRate(Vec2(1,0));
addChild(left);
left->setPosition(100,100);
left->runAction(RepeatForever::create(t6->clone()));
left->runAction(RepeatForever::create(hint->clone()));
使用缓存中图片加载进度条,通过加载plist文件
auto t7 =
Sequence::createWithTwoActions(ProgressTo::create(6,100),ProgressTo::create(0,0));
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");
auto left =
ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png"));
left->setMidpoint(Vec2(0.5f,0.5f));
left->setBarChangeRate(Vec2(1,0));
addChild(left);
left->setPosition(300,300);
left->runAction(RepeatForever::create(t7->clone()));