Forum > Extensions > Port of YannickL's CCControlExtensions to cocos2d-x

Port of YannickL's CCControlExtensions to cocos2d-x

By veggiesaurus Posted 2012-02-14 22:53 Comments 28
veggiesaurus
  • Posts: 17

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;
slider~~>setMaximumValue(max);
slider~~>setSnappingInterval;
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
  • Posts: 49

#1 RE: 2012-03-16 06:30

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.

veggiesaurus
  • Posts: 17

#2 RE: 2012-03-16 09:54

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
  • Posts: 49

#3 RE: 2012-03-19 06:17

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?

veggiesaurus
  • Posts: 17

#4 RE: 2012-03-19 11:15

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
  • Posts: 49

#5 RE: 2012-03-20 01:12

ok I make a CCScale9Sprite.cpp.

CCScale9Sprite.cpp (12.9 kB)

sangtaik
  • Posts: 49

#6 RE: 2012-03-20 01:17

this is header file

using tip

const CCSize sizeBackground = CCSizeMake(200, 200);

CCScale9Sprite* background = CCScale9Sprite::spriteWithFile( “background.png”);
background~~>setContentSize;
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
  • Posts: 49

#7 RE: 2012-03-20 01:19

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

veggiesaurus
  • Posts: 17

#8 RE: 2012-03-20 09:32

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,

blurg
  • Posts: 28

#9 RE: 2012-04-01 15:27

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.

veggiesaurus
  • Posts: 17

#10 RE: 2012-04-01 15:31

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

blurg
  • Posts: 28

#11 RE: 2012-04-01 15:40

oooh ok thanks :)

dumganhar
  • Posts: 999

#12 RE: 2012-04-16 09:08

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
  • Posts: 141

#13 RE: 2012-04-21 01:14

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.

jandujar
  • Posts: 175
  • Location: Spain

#14 RE: 2012-05-10 10:08

plz, upload the demo.

;)

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

veggiesaurus
  • Posts: 17

#15 RE: 2012-05-15 19:28

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

jandujar
  • Posts: 175
  • Location: Spain

#16 RE: 2012-05-15 19:36

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 10m downloads of my first game "Guess the Character"

veggiesaurus
  • Posts: 17

#17 RE: 2012-05-15 19:37

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

jandujar
  • Posts: 175
  • Location: Spain

#18 RE: 2012-05-17 15:19

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

jandujar
  • Posts: 175
  • Location: Spain

#19 RE: 2012-05-17 15:25

CCControlExtensions updated to the latest supplied by Angus Comrie.

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

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

winipcfg
  • Posts: 141

#20 RE: 2012-05-18 14:06

Where can I find GameState.h?

veggiesaurus
  • Posts: 17

#21 RE: 2012-05-18 15:56

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

jandujar
  • Posts: 175
  • Location: Spain

#22 RE: 2012-05-24 08:10

solved the references to GameState inside cocos2d-x-extensions

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

hioscar
  • Posts: 2

#23 RE: 2012-06-05 02:31

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.

jandujar
  • Posts: 175
  • Location: Spain

#24 RE: 2012-06-07 12:48

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 10m downloads of my first game "Guess the Character"

llazyworm
  • Posts: 9

#25 RE: 2012-09-06 22:49

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.

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps