Cocos2d-x实现游戏怪物血条血条

最近刚接触cocos2d  在需求中需要血条,顺便写个

首先自己写个方法

//怪物血条
void Fighting::getBloodbar(MenuItemImage  *guaisprite ,float a){ //guaispirte为怪物精灵的参数
CCSprite *pBloodKongSp = CCSprite::create("b.png");//空血条
pBloodKongSp->setPosition(Vec2(guaisprite->getContentSize().width / 2, guaisprite->getContentSize().height / 1.1));
guaisprite->addChild(pBloodKongSp);
CCSprite *pBloodManSp = CCSprite::create("z.png");//满血条
CCProgressTimer *pBloodProGress = CCProgressTimer::create(pBloodManSp);
pBloodProGress->setType(kCCProgressTimerTypeBar);
pBloodProGress->setBarChangeRate(Vec2(1, 0));
pBloodProGress->setMidpoint(Vec2(0, 0));
pBloodProGress->setPosition(Vec2(guaisprite->getContentSize().width / 2, guaisprite->getContentSize().height / 1.1));
pBloodProGress->setPercentage(a);
guaisprite->addChild(pBloodProGress, 1, 1);
}

在init中直接调用  传参数即可使用

 this->getBloodbar(guan1,20.0f);

你可能感兴趣的:(cocos2d-x,cocos2d)