Angus Comrie Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie over 1 year ago

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->setMinimumValue(min);
slider->setMaximumValue(max);
slider->setSnappingInterval(snappingInterval);
slider->setValue(value);
slider->addTargetWithActionForControlEvents(this, menu_selector(MenuScene::sliderCallback), CCControlEventValueChanged);
return slider;

Some pics:
http://imgur.com/YtBpT
http://imgur.com/IVjPF

And finally an example of it in action:
http://www.youtube.com/watch?v=NHA6uB2_D_s

SangTaik Jung RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 40
Added by SangTaik Jung about 1 year ago

your good job is very helpful.:)
but I can't work because "Extensions\CCScale9Sprite.h"

where I get the file and folder?

Thank you for your work.

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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 :)

SangTaik Jung RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 40
Added by SangTaik Jung about 1 year ago

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)(sender); // 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?

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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.

SangTaik Jung RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 40
Added by SangTaik Jung about 1 year ago

ok I make a CCScale9Sprite.cpp.

CCScale9Sprite.cpp (12.9 kB)

SangTaik Jung RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 40
Added by SangTaik Jung about 1 year ago

this is header file

using tip

const CCSize sizeBackground = CCSizeMake(200, 200);
CCScale9Sprite* background = CCScale9Sprite::spriteWithFile( "background.png");
background->setContentSize( sizeBackground );
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.

SangTaik Jung RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 40
Added by SangTaik Jung about 1 year ago

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

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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,
blue eur RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 28
Added by blue eur about 1 year ago

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.

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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

blue eur RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 28
Added by blue eur about 1 year ago

oooh ok thanks :)

James Chen RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 637
Added by James Chen about 1 year ago

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

winipcfg winipcfg RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 56
Added by winipcfg winipcfg about 1 year ago

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.

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar about 1 year ago

plz, upload the demo.

;)

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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 :)

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 :)

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 ;)

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar about 1 year ago

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.
http://www.cocos2d-x.org/boards/18/topics/11080
https://github.com/jandujar/cocos2d-x-extensions

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

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

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar about 1 year ago

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar about 1 year ago

CCControlExtensions updated to the latest supplied by Angus Comrie.

https://github.com/jandujar/cocos2d-x-extensions

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

winipcfg winipcfg RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 56
Added by winipcfg winipcfg about 1 year ago

Where can I find GameState.h?

Angus Comrie RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 17
Added by Angus Comrie about 1 year ago

any missing files should be available https://github.com/jandujar/zatacka-clone-cocos2d-x

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar about 1 year ago

solved the references to GameState inside cocos2d-x-extensions

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

yunhai shen please help,thank you! how can i have a button with a state changed when the mouse move on it in win32
Posts 2
Added by yunhai shen 12 months ago

thnak you and your hard woking, i git on the web, https://github.com/jandujar/cocos2d-x-extensions, i saw the source <void CCButton::initWithFile> but it doesn't include the move in state picture! can you give some tips,thanks.

Jose Antonio Andujar RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 82
Location Spain
Added by Jose Antonio Andujar 12 months ago

I only copy the source from http://www.cocos2d-x.org/boards/18/topics/7963

I don't understand your question

http://www.jandusoft.com
More than 7m downloads of my first game "Guess the Character"

worm wang RE: Port of YannickL's CCControlExtensions to cocos2d-x
Posts 9
Added by worm wang 9 months ago

Jose Antonio Andujar wrote:

I only copy the source from http://www.cocos2d-x.org/boards/18/topics/7963

I don't understand your question

cool, thanks.


(1-25/25)