I’ve ported the very nice set of extensions to cocos2d made by YannickL (https://github.com/YannickL/CCControlExtension) to cocos2d-x.
The controls are:
- Scale9Sprite (resizable 9patch sprite)
- ControlButton (button with excellent event handling, with a label and background 9patch sprite
- Color picker
I have made a few adjustments to YannickL’s code: The slider now has a the ability to “snap” to certain intervals. For example, if the slider goes from 1-10, you could make it snap to integers only. In addition, the touch detection has been cleaned up a bit to allow for more intuitive slides.
If anyone wants to have a look, they’re attached here. You can use the images from YannickL’s github for testing. You can create slider with the following code:
@ CCControlSlider* slider=CCControlSlider::sliderFromFiles(“Slider.png”, “SliderProgress.png”, “SliderKnob.png”);
slider->addTargetWithActionForControlEvents(this, menu_selector(MenuScene::sliderCallback), CCControlEventValueChanged);
And finally an example of it in action:
CCControlExtension.zip (34.7 KB)