1

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

4

1 回答 1

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];
于 2012-12-25T21:57:12.330 回答