Cocos2d-x UI開辟之CCControlPotentiometer控件類應用實例。本站提示廣大學習愛好者:(Cocos2d-x UI開辟之CCControlPotentiometer控件類應用實例)文章只能為提供參考,不一定能成為您想要的結果。以下是Cocos2d-x UI開辟之CCControlPotentiometer控件類應用實例正文
CCControlPotentiometer是電位計按鈕,和CCControlSlider的用法很類似。關於控件應用時的一些設置裝備擺設,請拜見文章:UI開辟之控件類-CCControlButton。
bool HelloWorld::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); //CCControlPotentiometer參數是底座,進度條,掌握按鈕圖片資本 CCControlPotentiometer * potentiometer = CCControlPotentiometer::create("potentiometerTrack.png", "potentiometerProgress.png","potentiometerButton.png"); //設置最年夜值和最小值和初值 potentiometer->setMaximumValue(100.0); potentiometer->setMinimumValue(0.0); potentiometer->setValue(50); potentiometer->setPosition(ccp(240,160)); this->addChild(potentiometer); //添加事宜監聽 potentiometer->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::valueChanged), CCControlEventValueChanged); bRet = true; } while(0); return bRet; } void HelloWorld::valueChanged(CCObject * pSender,CCControlEvent controlEvent) { CCControlPotentiometer * potentiometer = (CCControlPotentiometer *)pSender; CCString * string = CCString::createWithFormat("%f",potentiometer->getValue()); CCLog(string->getCString()); }