展会信息港展会大全

Cocos2d-x UI开发之CCControlPotentiometer控件类使用实例
来源:互联网   发布日期:2015-09-28 10:42:39   浏览:1140次  

导读: CCControlPotentiometer是电位计按钮,和CCControlSlider的用法很相似。关于控件使用时的一些配置,请参见文章:UI开发之控件类-CCControlButton。...

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());

}

赞助本站

人工智能实验室
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港