cocos2dx之创建CCControlSlider

采用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);
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值