c++progress-barcocos2d-xcocos2d-x-3.0

Move progress bar from left to right in cocos2d-x 3.2


I am using the following code to make a progress bar in cocos2d-x 3.2.

Sprite *fuelBarBorder;

fuelBarBorder = CCSprite::create("ui_kbg.png");

fuelBarBorder->setPosition(_visibleSize.width/2,_visibleSize.height/2);

this->addChild(fuelBarBorder, 1);


CCProgressTimer *fuelBar;
fuelBar = CCProgressTimer::create( CCSprite::create("slt_bg.png"));

// Set this progress bar object as kCCProgressTimerTypeBar (%)
fuelBar->setType(ProgressTimerType::BAR);

// Set anchor point in 0,0 and add it as a child to our border sprite
fuelBar->setAnchorPoint(ccp(0, 0));

fuelBar->setBarChangeRate(ccp(1, 0)); // To make width 100% always
fuelBar->setTag(1);                  // Tag our object for easy access

fuelBarBorder->addChild(fuelBar, 50); // Add it inside the border sprite

Issue is bar in moving from center to both directions (i.e L and R), I want to move it in LR direction, how can I do this?


Solution

  • Use fuelBar->setMidpoint(Vec2(0.0f, 0.1f)); for LR direction.