[Cocos2d-x For WP8]Progress 进度条
2013-08-21 22:52
423 查看
Cocos2d-x可以有多种进度条的展示方式,进度条的种类是根据进度条运动的方向来区分,包括顺时针,逆时针,从左到右,从右到左,从下到上和从上到下6种方式,这和WP8的进度条是由很大的区别的。那么Cocos2d-x的进度条是需要用图片来进行展示,然后从不同的方向来渐渐把图片显示出来实现进度条的效果。
第一步需要创建一个CCProgressTo对象和CCProgressTimer对象,我们可以通过CCProgressTo::create(2, 100)方法创建CCProgressTo定义了进度条的时间和图片的百分比,第一个参数是时间是一个CCTime对象,第二个参数是结果显示图片的百分比。通过CCProgressTimer::progressWithFile("cat.png")方法创建CCProgressTimer定义了进度条的图片文件。
CCProgressTo *to1 = CCProgressTo::create(2, 100);
CCProgressTimer *left = CCProgressTimer::progressWithFile("cat.png");
第二步通过CCProgressTimer指针设置进度条的类型。
调用setType设置类型,
kCCProgressTimerTypeRadialCW 顺时针生成
kCCProgressTimerTypeRadialCCW 逆时针生成
kCCProgressTimerTypeHorizontalBarLR 从左到右生成
kCCProgressTimerTypeHorizontalBarRL 从右到左生成
kCCProgressTimerTypeVerticalBarBT 从下到上生成
kCCProgressTimerTypeVerticalBarTB 从上到下生成
left->setType( kCCProgressTimerTypeRadialCW );
第三步添加到场景,设置位置和重复的频率
addChild(left);
left->setPosition(CCPointMake(100, size.height*3/4));
left->runAction( CCRepeatForever::create(to1));
示例代码:
运行的效果:
第一步需要创建一个CCProgressTo对象和CCProgressTimer对象,我们可以通过CCProgressTo::create(2, 100)方法创建CCProgressTo定义了进度条的时间和图片的百分比,第一个参数是时间是一个CCTime对象,第二个参数是结果显示图片的百分比。通过CCProgressTimer::progressWithFile("cat.png")方法创建CCProgressTimer定义了进度条的图片文件。
CCProgressTo *to1 = CCProgressTo::create(2, 100);
CCProgressTimer *left = CCProgressTimer::progressWithFile("cat.png");
第二步通过CCProgressTimer指针设置进度条的类型。
调用setType设置类型,
kCCProgressTimerTypeRadialCW 顺时针生成
kCCProgressTimerTypeRadialCCW 逆时针生成
kCCProgressTimerTypeHorizontalBarLR 从左到右生成
kCCProgressTimerTypeHorizontalBarRL 从右到左生成
kCCProgressTimerTypeVerticalBarBT 从下到上生成
kCCProgressTimerTypeVerticalBarTB 从上到下生成
left->setType( kCCProgressTimerTypeRadialCW );
第三步添加到场景,设置位置和重复的频率
addChild(left);
left->setPosition(CCPointMake(100, size.height*3/4));
left->runAction( CCRepeatForever::create(to1));
示例代码:
//逆时针转动 CCProgressTo *to1 = CCProgressTo::create(2, 100); CCProgressTimer *left = CCProgressTimer::progressWithFile("cat.png"); left->setType( kCCProgressTimerTypeRadialCW ); addChild(left); left->setPosition(CCPointMake(100, size.height*3/4)); left->runAction( CCRepeatForever::create(to1)); //顺时针转动 CCProgressTo *to2 = CCProgressTo::create(2, 100); CCProgressTimer *right = CCProgressTimer::progressWithFile("cat.png"); right->setType( kCCProgressTimerTypeRadialCCW ); addChild(right); right->setPosition(CCPointMake(100, size.height/4)); right->runAction( CCRepeatForever::create(to2)); //从左到右 CCProgressTo *toHorizontalBar1 = CCProgressTo::create(2, 100); CCProgressTimer *leftHorizontalBar = CCProgressTimer::progressWithFile("cat.png"); leftHorizontalBar->setType( kCCProgressTimerTypeHorizontalBarLR ); addChild(leftHorizontalBar); leftHorizontalBar->setPosition(CCPointMake(400, size.height*3/4)); leftHorizontalBar->runAction( CCRepeatForever::create(toHorizontalBar1)); //从右到左 CCProgressTo *toHorizontalBar2 = CCProgressTo::create(2, 100); CCProgressTimer *rightHorizontalBar = CCProgressTimer::progressWithFile("cat.png"); rightHorizontalBar->setType( kCCProgressTimerTypeHorizontalBarRL ); addChild(rightHorizontalBar); rightHorizontalBar->setPosition(CCPointMake(400, size.height/4)); rightHorizontalBar->runAction( CCRepeatForever::create(toHorizontalBar2)); //从底部到顶部 CCProgressTo *toVerticalBar1 = CCProgressTo::create(2, 100); CCProgressTimer *leftVerticalBar = CCProgressTimer::progressWithFile("cat.png"); leftVerticalBar->setType( kCCProgressTimerTypeVerticalBarBT ); addChild(leftVerticalBar); leftVerticalBar->setPosition(CCPointMake(700, size.height*3/4)); leftVerticalBar->runAction( CCRepeatForever::create(to1)); //从顶部到底部 CCProgressTo *toVerticalBar2 = CCProgressTo::create(2, 100); CCProgressTimer *rightVerticalBar = CCProgressTimer::progressWithFile("cat.png"); rightVerticalBar->setType( kCCProgressTimerTypeVerticalBarTB ); addChild(rightVerticalBar); rightVerticalBar->setPosition(CCPointMake(700, size.height/4)); rightVerticalBar->runAction( CCRepeatForever::create(toVerticalBar2));
运行的效果:
相关文章推荐
- Cocos2d-x教程(10)-CCProgressTimer实现页面加载进度条效果
- [Cocos2d-x for WP8学习笔记] HelloWorld
- Cocos2d-x学习笔记(14)(更新函数scheduleUpdate、进度计时器CCProgressTo、滚动视图CCScrollView)
- [Cocos2d-x For WP8]MotionStreak拖尾效果
- [Cocos2d-x For WP8]Scene场景
- [Cocos2d-x For WP8]Transition 场景切换
- [Cocos2d-x For WP8]EaseActions缓动动作
- [Cocos2D-x For WP8]Sprite精灵
- 【Cocos2d-x for WP8 学习整理】(1)创建一个新项目
- [Cocos2d-x For WP8]Effects 特效
- [Cocos2d-x For WP8]Particle粒子系统
- [Cocos2D-x For WP8]Label标签
- 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源
- [Cocos2D-x For WP8]Box2D物理引擎
- [Cocos2d-x For WP8]点击移动精灵
- 【Cocos2d-x for WP8 学习整理】(3)CCScrollView 实现捕鱼达人一样的场景选择界面
- Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主
- [Cocos2d-x for WP8学习笔记] 获取系统字体
- [Cocos2d-x For WP8]Hello world
- [Cocos2d-x For WP8]基础知识