标签:cocos2d
最近刚接触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
原文地址:http://blog.csdn.net/u010319687/article/details/39007583