Port of YannickL's CCControlExtensions to cocos2d-x

Port of YannickL's CCControlExtensions to cocos2d-x
0.0 0


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
  • Slider
  • 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);
return slider;

Some pics:

And finally an example of it in action:

CCControlExtension.zip (34.7 KB)


your good job is very helpful.:slight_smile:
but I can’t work because “Extensions\CCScale9Sprite.h”

where I get the file and folder?

Thank you for your work.


this should do the trick, I think this is the unmodified version of CCScale9Sprite (I’ve made some changes to it, so I had to dig around for the original.) Good luck, and let me know if you get it working :slight_smile:


ok I make a CCScale9Sprite class now.
but your code have a error in CCInvocation.cpp

invoke() method

if (m_pTarget && m_action)
(m_pTarget->**m_action); // error

Semantic Issue: Left hand operand to ->** must be a pointer to class compatible with the right hand operand, but is ‘cocos2d::CCObject *’

Why? do you know this error?

hm. What is CCInvocation class?
is it same CCMenuItem active() method?


that’s odd, I’ve never seen that error before. The invocation object is basically a collection of a target and a function pointer. The invoke method just calls the function belonging to the target object, passing in the object that called the invoke as the argument.

I’m not sure, but you might need some extra brackets on the (*m_action), but the code works fine for me in VS2010.


ok I make a CCScale9Sprite.cpp.


this is header file

using tip

const CCSize sizeBackground = CCSizeMake(200, 200);

CCScale9Sprite* background = CCScale9Sprite::spriteWithFile( “background.png”);
background~~>setPosition( ccp(100,100 ) );

core function is setContentSize;

I want to make a rect for stretch, but spriteWithXXXX is not work.

I don’t know Why. Value is corrected

and setAnchorPoint is not work.

please help me anyone.


Thanks Angus Comrie. I want to make a better this class. but I am not expert. have a sentence me for better. Thank you.


I think you have to call it like:

CCScale9Sprite::scale9SpriteWithFile("ButtonNormal.png", CCRect(24, 10, 48, 44));

the CCRect specifies the region that can be stretched,


Thanks for this extension, I would like to use the scale 9 feature. What are the file that I have to use ? I can’t find the scale9sprite files in the zip here : http://cocos2d-x.org/projects/cocos2d-x/assets/1 so I’m not sure of what to use.


The scale9 sprite source files are in the third post on this page :slight_smile:


oooh ok thanks :slight_smile:


Hi, all,
Could you please upload the demo code in the video? :slight_smile:
We are considering to merge this cool feature into our gles20 branch.


Thanks. It looks great.

I found an issue on CCControlButton. It crashes if you use “buttonWithTitleAndFontNameAndFontSize” method in CCControlButton.
It is due to missing CCScale9Sprite.


plz, upload the demo.



Sorry for the delay. I have attached the source code for my little game: http://www.youtube.com/watch?v=izYhpK7Z_zo

EDIT: for some reason, it’s not uploading. Can someone try to upload it from here: http://dl.dropbox.com/u/2522035/HelloWorld.rar
It’s basically a remake of Zatacka (Achtung die Kurve) for iOS and Android. If you think it looks too similar to a few of the versions already out there, it’s because they might’ve kinda “borrowed” the style from my xbox version :slight_smile:

Anyway, so it contains the CCControlExtensions, as well as a few of my nice extensions to these extensions:

  • Snapping to integer values for the slider
  • checkboxes
  • “Passive” menus (which allow the controls to handle events)
  • Spacers
  • “Setting” controls, which can be tied to a value in CCUserDefaults

The actual game shows how to handle multiple touches, how to scale the UI for different devices (I probably went a bit overboard here, because it automatically selects the best asset size based on the screen size, as well as the available asset sizes (240p, 320p, 480p, etc. It’s dynamic). It’s also quite fun to play on a tablet! Free to use/abuse however you want, just not for a snake-based game :slight_smile:

I’m pretty sure my coding style is not ideal, and I’m also sure there are better ways to get some things done, but it works :wink:


can I upload your game to github? giving you the credits of course. Or maybe you can upload it.

I will upload your extensions to my cocos2d-x-extensions branch.


of course :slight_smile: if you have any questions about it, just drop me a mail


uploaded the game to github.


CCControlExtensions updated to the latest supplied by Angus Comrie.