2013-07-18 59 views
1

我是Cocos2d-x中的新手。Cocos2d-x:創建簡單的進度條

我要創建我的遊戲簡單的進度/更新吧。

當這個進度條滿,我們將移動到一個新的水平。

我怎樣才能創建一個吧。

感謝您的幫助。

回答

2

請參閱本 - How to use a progress bar in cocos2d-x and C++

基本上,創建兩個精靈一個進度條的邊框和一個用於加載條本身。

CCPointer fuelBarBorder; 

fuelBarBorder = 
    CCSprite::createWithSpriteFrameName ("bt_progressbarborder.png"); 
fuelBarBorder->setPosition(ccp(100,100)); 
this->addChild(fuelBarBorder,1); 




// CCProgresstimer object (smart pointer) 
CCPointer fuelBar; 
fuelBar = CCProgressTimer::create(
    CCSprite::createWithSpriteFrameName ("bt_progressbar.png")); 

將加載欄精靈的類型設置爲CCProgressTimerType

// Set this progress bar object as kCCProgressTimerTypeBar (%) 
fuelBar->setType(CCProgressTimerType::kCCProgressTimerTypeBar); 

// Set anchor point in 0,0 and add it as a child to our border sprite 
fuelBar->setAnchorPoint(ccp(0,0)); 

fuelBar->setBarChangeRate(ccp(1,0)); // To make width 100% always 
fuelBar->setTag(1);     // Tag our object for easy access 

fuelBarBorder->addChild(fuelBar,50); // Add it inside the border sprite 

在你更新的方法,改變其percentage,以反映負載百分比。

fuelBar->setPercentage(80); // Value between 0-100 
+0

我嘗試但CCPointer不存在,我不知道爲什麼。 – Tom

+0

我已經得到的Cocos2D-X – Tom

+0

@湯姆的最新的vesion只使用'CCSprite'到位CCPointer'的',它應該工作 – asloob

0

我寫了原文(上面的鏈接)。

多虧了這個帖子,我發現WordPress的發揮我...保存代碼:(當

還有就是要進行一些修正。

CCPointer <CCSprite> fuelBarBorder; 

fuelBarBorder = 
    CCSprite::createWithSpriteFrameName ("bt_progressbarborder.png"); 

fuelBarBorder->setPosition(ccp(100,100)); 

this->addChild(fuelBarBorder,1); 

這對於首套,你可以看到的唯一的變化是在第一行:

CCPointer <CCSprite> fuelBarBorder; 

如果沒有這個的cocos2d-X擴展,只需使用以下命令:

CCSprite * fuelBarBorder; 

同在第二組代碼,正確的是:

CCPointer <CCProgressTimer> fuelBar; 

fuelBar = CCProgressTimer::create(
CCSprite::createWithSpriteFrameName ("bt_progressbar.png")); 
// Set this progress bar object as kCCProgressTimerTypeBar (%) 
fuelBar->setType(CCProgressTimerType::kCCProgressTimerTypeBar); 

// Set anchor point in 0,0 and add it as a child to our border sprite 
fuelBar->setAnchorPoint(ccp(0,0)); 

fuelBar->setBarChangeRate(ccp(1,0)); // To make width 100% always 
fuelBar->setTag(1);     // Tag our object for easy access 

fuelBarBorder->addChild(fuelBar,50); // Add it inside the border sprite 
是使用CCPointer(智能指針實現),如果你沒有在您的項目,只是改變

同樣的事情下列行:

CCPointer <CCProgressTimer> fuelBar; 

由這一個:

CCProgressTimer fuelBar; 

的這應該毫安代碼的作品,我希望這有助於!