Cocos2d-x CCControlPotentiometer控件类使用实例 Cocos2d-x UI开发之CCControlPotentiometer控件类使用实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Cocos2d-x CCControlPotentiometer控件类使用实例 Cocos2d-x UI开发之CCControlPotentiometer控件类使用实例

  2021-03-19 我要评论
想了解Cocos2d-x UI开发之CCControlPotentiometer控件类使用实例的相关内容吗,在本文为您仔细讲解Cocos2d-x CCControlPotentiometer控件类使用实例的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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());
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们