CCPocressTimer在cocos2D中

时间:2012-12-09 15:40:07

标签: ios cocos2d-iphone

也许这个问题已经重复了很多次,但我找不到有用的材料。这也是我在cocos2D中的第一个项目,我想在cocos2D中实现ProgressBar,CCProgressTimer。我有两个精灵,第一个是移动,第二个是玩家(你可以移动),如果用户成功吃第一个移动物体,那么进展应该增加,否则如果它没有,则进度将减少。我需要你的帮助。提前致谢。

1 个答案:

答案 0 :(得分:4)

这是我用于舍入CCProgressTimers的代码(它看起来像时钟)。你可能需要在背景精灵上面有一个背景精灵和一个“可移动”的精灵。

CCSprite *movableSprite = [CCSprite spriteWithFile:@"health100.png"];
CCProgressTimer *healthBar = [CCProgressTimer progressWithSprite:movableSprite];
healthBar.type = kCCProgressTimerTypeRadial; // This is for round progress timer. Possible value for horizontal bar will be kCCProgressTimerTypeHorizontalBarLR

healthBar.midpoint = ccp(0,0.5); // Here is where all magic is
healthBar.barChangeRate = ccp(1, 0); // If you need horizontal bar progress play with these parameters.

// Here we will start an animation process. 
// You can do it without animation just setting up healthBar.progress = 45.0f; (45%)
[healthBar runAction:[CCProgressFromTo actionWithDuration:2.0f from:0.0f to:100.0f]];        

healthBar.position = ccp(100, 100); // It's your position

[self addChild:healthBar];