直接上代码
//背景图片,
auto* hpBgSprite = Sprite::create("hpbg.png");
hpBgSprite->setPosition(Point(visibleSize.width/2, visibleSize.height/2-100 ));
this->addChild(hpBgSprite);
//有血量的图片
auto hpBar = CCProgressTimer::create(Sprite::create("hp.png"));
hpBar->setType(ProgressTimer::Type::BAR);
hpBar->setMidpoint(Point(0, 0.5f));
hpBar->setBarChangeRate(Point(1, 0));
hpBar->setPercentage(50);//血量
hpBar->setPosition(Point(0,0));//坐标点,相对于背景的
hpBar->setAnchorPoint(Point(0,0));//锚点
hpBgSprite->addChild(hpBar);