CCProgressTimer进度条比LoadingBar靠谱

CCProgressTimer是ccnode的子类,可以用作水平、垂直、圆形的进度条
创建一个进度条

local spr = display.newSprite("xx.png")
local pg  = CCProgressTimer:create(spr)
local bg = display.newSprite("bg.png")
bg:addChild(pg)
pg:setType(kCCProgressTimerTypeBar)  -- 进度条
pg:setPercentage(0) 
/** 
 *    Midpoint is used to modify the progress start position. 
 *    If you're using radials type then the midpoint changes the center point 
 *    If you're using bar type the the midpoint changes the bar growth 
 *        it expands from the center but clamps to the sprites edge so: 
 *        you want a left to right then set the midpoint all the way to ccp(0,y) 
 *        you want a right to left then set the midpoint all the way to ccp(1,y) 
 *        you want a bottom to top then set the midpoint all the way to ccp(x,0) 
 *        you want a top to bottom then set the midpoint all the way to ccp(x,1) 
*/  
pg:setMidpoint(ccp(0,0)) -- 这里设置起点 0,0为最左边 1,0为最右边 0,1为最上面
/** 
 *    This allows the bar type to move the component at a specific rate 
 *    Set the component to 0 to make sure it stays at 100%. 
 *    For example you want a left to right bar but not have the height stay 100% 
 *    Set the rate to be ccp(0,1); and set the midpoint to = ccp(0,.5f); 
*/  

-- 哪个方向变化哪个方向就是1,左右变化 ccp(1,0) 上下变化 ccp(0,1)
pg:setBarChangeRate(ccp(1, 0)) 
local ac = CCProgressFromTo:create(0.5,0, 100)
pg:runAction(ac)

重点是setMidpoint与setBarChangeRate的组合可以实现四种方向的进度条
若是 kCCProgressTimerTypeRadial 模式 是从圆的中心开始转
具体参考一下cocos的示例吧

你可能感兴趣的:(进度条)