采用CCControlSlider创建,代码如下:
CCControlSlider *slider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5, 1.0f)); slider->setPosition(ccp(visibleSize.width / 2.0f, visibleSize.height / 2.0f)); slider->setMinimumValue(0.1f); slider->setMaximumValue(100.0f); slider->setTag(1); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::valueChange), CCControlEventValueChanged); this->addChild(slider, 1);
/** Kinds of possible events for the control objects. */ enum { CCControlEventTouchDown = 1 << 0, // A touch-down event in the control. CCControlEventTouchDragInside = 1 << 1, // An event where a finger is dragged inside the bounds of the control. CCControlEventTouchDragOutside = 1 << 2, // An event where a finger is dragged just outside the bounds of the control. CCControlEventTouchDragEnter = 1 << 3, // An event where a finger is dragged into the bounds of the control. CCControlEventTouchDragExit = 1 << 4, // An event where a finger is dragged from within a control to outside its bounds. CCControlEventTouchUpInside = 1 << 5, // A touch-up event in the control where the finger is inside the bounds of the control. CCControlEventTouchUpOutside = 1 << 6, // A touch-up event in the control where the finger is outside the bounds of the control. CCControlEventTouchCancel = 1 << 7, // A system event canceling the current touches for the control. CCControlEventValueChanged = 1 << 8 // A touch dragging or otherwise manipulating a control, causing it to emit a series of different values. };
还可以建立色盘,利用CCControlColourPicker,具体代码如下:
void MyControlLayerItem::initLayer() { CCSize size = CCDirector::sharedDirector()->getWinSize(); CCControlColourPicker *control = CCControlColourPicker::create(); control->setPosition(ccp(size.width / 3.0f, size.height / 3.0f)); control->setColor(ccc3(255, 0, 0)); control->addTargetWithActionForControlEvents( this, cccontrol_selector(MyControlLayerItem::valueChange), CCControlEventValueChanged); this->addChild(control, 2); }