#include "../CCControlScene.h"

class CCControlSliderTest : public CCControlScene
{
public:
CCControlSliderTest();
virtual ~CCControlSliderTest();
bool init();
void valueChanged(CCObject *sender, CCControlEvent controlEvent);
protected:
CCLabelTTF* m_pDisplayValueLabel;
CONTROL_SCENE_CREATE_FUNC(CCControlSliderTest)
};
CCControlSliderTest::~CCControlSliderTest()
{
CC_SAFE_RELEASE_NULL(m_pDisplayValueLabel);
}
bool CCControlSliderTest::init()
{
if (CCControlScene::init())
{
CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add a label in which the slider value will be displayed
m_pDisplayValueLabel = CCLabelTTF::create("Move the slider thumb!\nThe lower slider is restricted." ,"Marker Felt", );
m_pDisplayValueLabel->retain();
m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1.0f));
m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 1.7f, screenSize.height / 2.0f));
addChild(m_pDisplayValueLabel); // Add the slider
//第一个参数是背景,第二个参数是进度条,第三个参数表示拖动按钮
CCControlSlider *slider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
slider->setAnchorPoint(ccp(0.5f, 1.0f));
slider->setMinimumValue(0.0f); // Sets the min value of range
slider->setMaximumValue(5.0f); // Sets the max value of range
slider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + ));
slider->setTag(); // When the value of the slider will change, the given selector will be call
//当进度值改变时,触发的函数
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlSliderTest::valueChanged), CCControlEventValueChanged); CCControlSlider *restrictSlider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
restrictSlider->setAnchorPoint(ccp(0.5f, 1.0f));
restrictSlider->setMinimumValue(0.0f); // Sets the min value of range
restrictSlider->setMaximumValue(5.0f); // Sets the max value of range
//设置允许的最大值和最小值
restrictSlider->setMaximumAllowedValue(4.0f);
restrictSlider->setMinimumAllowedValue(1.5f);
restrictSlider->setValue(3.0f);
restrictSlider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - ));
restrictSlider->setTag(); //same with restricted
restrictSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlSliderTest::valueChanged), CCControlEventValueChanged); addChild(slider);
addChild(restrictSlider);
return true;
}
return false;
}
void CCControlSliderTest::valueChanged(CCObject *sender, CCControlEvent controlEvent)
{
CCControlSlider* pSlider = (CCControlSlider*)sender;
// Change value of label.
if(pSlider->getTag() == )
m_pDisplayValueLabel->setString(CCString::createWithFormat("Upper slider value = %.02f", pSlider->getValue())->getCString());
if(pSlider->getTag() == )
m_pDisplayValueLabel->setString(CCString::createWithFormat("Lower slider value = %.02f", pSlider->getValue())->getCString());
}
//pSlider->getValue()可以获取滑动条的值

ControlExtensionTest(二)-----CCControlSlider的更多相关文章

  1. Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButtonbutton)

    CCEditBox.CCControlSwitch.CCControlSlider.CCControlColourPicker.CCControlButton等都是Cocos2d-x 2.x的最新UI ...

  2. 【小程序分享篇 二 】web在线踢人小程序,维持用户只能在一个台电脑持登录状态

    最近离职了, 突然记起来还一个小功能没做, 想想也挺简单,留下代码和思路给同事做个参考. 换工作心里挺忐忑, 对未来也充满了憧憬与担忧.(虽然已是老人, 换了N次工作了,但每次心里都和忐忑). 写写代 ...

  3. 前端开发中SEO的十二条总结

    一. 合理使用title, description, keywords二. 合理使用h1 - h6, h1标签的权重很高, 注意使用频率三. 列表代码使用ul, 重要文字使用strong标签四. 图片 ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  5. 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新

    上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...

  6. 谈谈一些有趣的CSS题目(十二)-- 你该知道的字体 font-family

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

  7. MIP改造常见问题二十问

    在MIP推出后,我们收到了很多站长的疑问和顾虑.我们将所有疑问和顾虑归纳为以下二十个问题,希望对大家理解 MIP 有帮助. 1.MIP 化后对其他搜索引擎抓取收录以及 SEO 的影响如何? 答:在原页 ...

  8. 如何一步一步用DDD设计一个电商网站(二)—— 项目架构

    阅读目录 前言 六边形架构 终于开始建项目了 DDD中的3个臭皮匠 CQRS(Command Query Responsibility Segregation) 结语 一.前言 上一篇我们讲了DDD的 ...

  9. ASP.NET Core 之 Identity 入门(二)

    前言 在 上篇文章 中讲了关于 Identity 需要了解的单词以及相对应的几个知识点,并且知道了Identity处在整个登入流程中的位置,本篇主要是在 .NET 整个认证系统中比较重要的一个环节,就 ...

随机推荐

  1. python mongodb ubuntu

    mongodb install: sudo apt-get install mongodb Install pip 1. $ sudo apt-get install python-pip pytho ...

  2. iOS多线程与网络开发之多线程NSThread

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...

  3. 解决 maven 项目启动 提示 class not find

    第一种方法: 项目 --> .classpath <classpathentry exported="true" kind="con" path=& ...

  4. Hibernate3.x异常No row with the given identifier exists 解决方法

    这个异常是在 多对一关系映射时,一方表中对应的数据不存在才抛出的.原来的配置: <many-to-one class="com.art.model.user.UserInfo" ...

  5. java 如何查看jdk版本&位数

      java 如何查看jdk版本&位数 CreateTime--2018年4月22日18:20:18 Author:Marydon 方式一:通过dos命令实现 win+R-->cmd-- ...

  6. 使用poi导出execl

    使用poi需要用到的jar包 本文的导出基于execl的模板导出,在大部分表头固定而格式花样比较复杂的建议使用本文介绍的方法(表头固定,只需要填充值) 1.在webroot目录下新建report文件夹 ...

  7. webservice系统学习笔记3-分析wsdl文件的组成

    详细分析前面章节的服务的wsdl文件 1.http://localhost:8888/ws01?wsdl 2.http://localhost:8888/ws01?xsd=1 在接口服务中添加复杂类型 ...

  8. 微信小程序独家秘笈之抽奖大转盘

    代码地址如下:http://www.demodashi.com/demo/14209.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  9. highstock高级篇之股票分时图

    一直在用 highchart 在做图表,最近一段时间突然接到一活,需要用 highstock 帮客户完成一个股票K线图和分时图.虽然用法和 api上与 highchart 没什么区别,但还是研究一番做 ...

  10. 【微信小程序】:评论、回复和删除功能 -- 2017/7/14

    1.理论核心:传参->pid,评论父id需要在wxml页面传递:小程序端和WEB端不同核心:前者操纵数据,后者操纵DOM元素对象 2.不废话,直接代码:wxml <view class=& ...