2012-12-09 29 views
1

也許這個問題已經重複了很多次,但我找不到有用的材料。這也是我在cocos2D中的第一個項目,我想在cocos2D中實現ProgressBar,CCProgressTimer。我有兩個精靈,第一個是移動的,第二個是玩家(你可以移動),如果用戶成功吃掉第一個移動物體,那麼進度應該增加,否則如果失敗,進度將減少。我需要你的幫助。提前致謝。cocos2D中的CCProgressTimer

+0

當玩家獲勝時,您可以在進度條中添加另一個精靈。不需要ccprogresstimer。或推送到一個數組,每次你贏了,進度條檢查數組的數量。這樣你就可以知道你有多少勝利。 –

回答

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];