Cocos2d-x中拖动滑块的控件类CCControlSlider使用
2013-07-13 18:52
429 查看
//包含头文件 #include"cocos-ext.h" USING_NS_CC_EXT; //使用命名空间extension //在init函数中加入 //_pSliderLabel为CCLabelTTF类型,用来显示滑块滑动时候的数字 _pSliderLabel = CCLabelTTF::create("", "", 30); _pSliderLabel->setPosition(ccp(200,200)); addChild(_pSliderLabel); //创建CCControlSlider空间,参数为背景图片,进度条图片,滑块图片 CCControlSlider *pSlider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png"); //设置最大最小值 pSlider->setMinimumValue(0.0f); pSlider->setMaximumValue(10.0f); pSlider->setPosition(ccp(size.width/3, size.height/3)); // 添加回调函数,当滑块被拖动时被调用 pSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::changeValue), CCControlEventValueChanged); /*参数三:Kinds of possible events for the control objects. CCControlEventTouchDown = 1 << 0, // A touch-down event in the control. CCControlEventTouchDragInside = 1 << 1, // An event where a finger is draggedinside the bounds of the control. CCControlEventTouchDragOutside = 1 << 2, // An event where a finger is draggedjust outside the bounds of the control. CCControlEventTouchDragEnter = 1 << 3, // An event where a finger is draggedinto the bounds of the control. CCControlEventTouchDragExit = 1 << 4, // An event where a finger is draggedfrom within a control to outside its bounds. CCControlEventTouchUpInside = 1 << 5, // A touch-up event in the controlwhere the finger is inside the bounds of the control. CCControlEventTouchUpOutside = 1 << 6, // A touch-up event in the controlwhere the finger is outside the bounds of the control. CCControlEventTouchCancel = 1 << 7, // A system event canceling thecurrent touches for the control. CCControlEventValueChanged = 1 << 8 // A touch dragging or otherwisemanipulating a control, causing it to emit a series of different values. */ addChild(pSlider); //添加回调函数 void HelloWorld::changeValue(CCObject *sender, CCControlEvent controlEvent) { CCControlSlider *pSlider = (CCControlSlider *)sender; //通过获取值来设置label的值 _pSliderLabel->setString(CCString::createWithFormat("value = %f", pSlider->getValue())->getCString()); } //编译连接,发现链接出错,无法解析的外部符号,汗啊。 //百度一下吧:原来是没有找到连接的文件 //解决办法: //右键项目属性->配置属性->链接器里面的附加依赖项,加上libCocosDenshion.lib和libExtensions.lib //搞定,哈哈。配图:
相关文章推荐
- cocos2d-x拖动滑块控件CCControlSlider
- cocos2d-x拖动滑块控件CCControlSlider
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- iOS cocos2d实现slider(滑块)控件效果源码
- iOS cocos2d实现slider(滑块)控件效果源码
- CSliderCtrl控件使用及滑块刻度提示
- Cocos2d-x控件使用CCControlSlider<代码演示>
- slider控件移动滑块,动态的显示tooltip方法!
- JS-slider.js实现鼠标拖动滑块控制取值特效
- WPF中Slider滑块的使用
- Cocos2d-x控件使用CCControlSwitch<代码演示>
- 使用iOS控件UICollectionView生成可拖动的桌面
- easyUI制作slider小滑块,可拖动和精确输入
- cocos2d-x中的Slider控件
- Android中SeekBar拖动条控件使用方法详解
- jQuery插件slider实现拖动滑块选取价格范围
- TextView,TextField,slider,segmented Control等各类控件的使用
- 使用JavaScript实现控件拖动