开发者

cocos2d progress bar

开发者 https://www.devze.com 2023-01-21 02:01 出处:网络
HI all, i am developing a puzzle game in iPhone using cocos2d.I need a progress bar (like uiprogres开发者_StackOverflow社区s bar) to show the game progress time.But i can\'t find any good example...

HI all,

i am developing a puzzle game in iPhone using cocos2d.I need a progress bar (like uiprogres开发者_StackOverflow社区s bar) to show the game progress time.But i can't find any good example...

can anyone tell me the way???


well....i get a better solution...here is my code

CCProgressFromTo *to1 = [CCProgressFromTo actionWithDuration:levelTimeLimit from:100 to:0];
    timeBar = [CCProgressTimer progressWithFile:@"Bar.png"];
    timeBar.type = kCCProgressTimerTypeHorizontalBarLR;
    [timeBar setPosition:ccp(384,84)];
    [self addChild:timeBar];
    [timeBar runAction:to1];

there is a class called CCProgressTimer in latest version of cocos2d..

thanks


You can use a CCSprite that you set the width of using

yourSprite.scaleX = 0.5 //This goes between 0.0 and 1.0.

You will have to calculate the required width, percentage and scaleX-factor manually but its pretty simple. I did my fiend hp bar implementation like this:

-(void)decreaseHp:(float)hpIn {
    self.hp = self.hp-hpIn;    //Decrease HP by specified amount.
    float p = (self.hp*100)/self.maxHp;    //Calculate new hp percentage.
    self.hpBar.scaleX = p/100;    //Convert percentage to a factor between 0 and 1.
}

self is the Fiend object and hpBar is a simple CCSprite with anchor ccp(0,0).

You you don't want you progress bar to stretch, but move instead, you will have to mask it with something and update its position instead of scaleX.

0

精彩评论

暂无评论...
验证码 换一张
取 消