Forums » Extensions and Tools » UIScrollView solution for cocos2d-x »
| leo leo | UIScrollView solution for cocos2d-x | ||||
|---|---|---|---|---|---|
|
Added by leo leo about 2 years ago
Hi everyone, I was looking for an UIScrollView like solution for cocos2d-x and all I could find is this great class named CCScrollView created by GParvaneh: Enjoy. update 27-6-2011: update files & add CCScrollLayerButton class (explained later in this post) CCScrollLayer.h (1.1 kB) CCScrollLayer.cpp (3.3 kB) CCScrollLayer.cpp (3.3 kB) CCScrollLayer.h (1.1 kB) CCScrollLayerButton.cpp (1.8 kB) CCScrollLayerButton.h (806 Bytes) |
||||
| Zhe Wang | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Zhe Wang about 2 years ago
Awesome. I will run it at Wednesday, after my short holiday finishes. Enjoy Coding, Enjoy Life. |
||||
| slash wong | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by slash wong about 2 years ago
@walzer |
||||
| Zhe Wang | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Zhe Wang about 2 years ago
WenSheng play with this source in this afternoon, and show me the effect. Enjoy Coding, Enjoy Life. |
||||
| Zhe Wang | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Zhe Wang almost 2 years ago
Hi,leo, we have created the "cocos2d-x-extensions" repository here http://github.com/cocos2d/cocos2d-x-extensions/ Enjoy Coding, Enjoy Life. |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo almost 2 years ago
the usage is very simple: @ CCScrollLayer* pScrollLayer = CCScrollLayer::layerWithLayers(&layers, 0); I don't know how to use git I'll be happy if you can apply it for me. |
||||
| qian xiang | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by qian xiang almost 2 years ago
it seemed no one has tested on android at all, even failed to compile. there is no CGPoint but CCPoint. |
||||
| Zhe Wang | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Zhe Wang almost 2 years ago
cocos2d::CGPoint is used in a very very old version Enjoy Coding, Enjoy Life. |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo almost 2 years ago
An updated version is attached. (using CCPoint) an example of usage: @ CCScrollLayer* pScrollLayer = CCScrollLayer::layerWithLayers(&layers, 0); // add scrollable buttons to layer 1 CCScrollLayer.cpp (3.3 kB) CCScrollLayer.h (1.1 kB) CCScrollLayerButton.cpp (1.8 kB) CCScrollLayerButton.h (806 Bytes) |
||||
| SangTaik Jung | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by SangTaik Jung almost 2 years ago
CCScrollButton is so awesome! very Thank you to you. But, I find a simple bug but very critical error. so I try to fix some source like that as* ccTouchEnded ( CCTouch* pTouch, CCEvent* pEvent )* if ( target != null && selector != null )
{ but I am not sure. |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo almost 2 years ago
Your fix is correct, but why would you want a Button without a selector? You can simply use CCSprite. |
||||
| SangTaik Jung | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by SangTaik Jung almost 2 years ago
Sometimes I make a source without selector. such as CCScrollLayerButton* level2Button = CCScrollLayerButton::buttonWithFile("sprite.png", null, null ); I got a reason why I remove a menu_selector. Because I don't know what I do for button event. I work for some great programmer, so I hope they should fill in button event. And I just start to program for 2 month with c++. |
||||
| SangTaik Jung | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by SangTaik Jung almost 2 years ago
I test some code using your source. I put it MenuItemSprite instead of CCSprite. Hm may be it is not complete code. However, I am sure if you want to change some function, it will be helpful. button change a image with selected Sprite. oh ye!
> class CCScrollLayerButton : public CCMenuItemSprite, CCTargetedTouchDelegate
> {
> ......
> }
> CCScrollLayerButton::initWithFile ( CCNode* normal, CCNode* selected, CCNode* disabled, SelectorProtocol* target, SEL_MenuHandler selector )
> {
> KDbool init = CCMenuItemSprite::initFromNormalSprite ( normal, selected, disabled, target, selector );
>
> if ( !init )
> {
> return false;
> }
> .....
>
> }
I got a normal sprite ( or ccprogress .. etc ) rect. Sometimes, CCProgress has a size parameter with 9.patch png.
> CCRect CCScrollLayerButton::rect ( KDvoid )
> {
> CCSize s = this->getNormalImage ( ) ->getContentSize ( );
> return CCRectMake ( -s.cx / 2, -s.cy / 2, s.cx, s.cy );
> }
the last change is so simple. just change parameter
> CCScrollLayerButton* CCScrollLayerButton::buttonWithFile ( CCNode* normal, CCNode* selected, CCNode* disabled, SelectorProtocol* target, SEL_MenuHandler selector )
> {
> CCScrollLayerButton *pRet = new CCScrollLayerButton ( );
>
> if ( pRet && pRet->initWithFile ( normal, selected, disabled, target, selector ) )
> {
> pRet->autorelease ( );
> return pRet;
> }
>
> CC_SAFE_DELETE ( pRet )
>
> return KD_NULL;
> }
|
||||
| Rowan Kerr | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Rowan Kerr over 1 year ago
What's the license on this? |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo over 1 year ago
Whatever you choose... |
||||
| vijay reddy | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by vijay reddy over 1 year ago
How to decrease the scroll width and height. |
||||
| vijay reddy | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by vijay reddy over 1 year ago
Scroll height and width. |
||||
| 小 苏 | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by 小 苏 over 1 year ago
it's good... well done. |
||||
| satish 1245 | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by satish 1245 about 1 year ago
i want reduce the layer size how can i do this.plz help me !! |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
Hi everybody, i hope you'll can help me. Thank you in advance. |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo about 1 year ago
Simply add the created CCScrollableButton to your scrollable layer and it will work. |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
Okay thanks a lot! I use the scroll layer class and it's work very well ;)! |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo about 1 year ago
You welcome! You may try my game as a thanks! |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
well, i would like to make a scrollable area, and when i scroll that area, all that is out of this area is not visible, how can I do that ? best regards |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo about 1 year ago
The only way to do this with the current implementation is to add a top layer above the scrollable layer that hides everything beside that area, maybe using a png with a transparent box within it. |
||||
| Ron Mobi | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Ron Mobi about 1 year ago
I used this solution in my project ! I changed some strings =) very usefull, thanks ! |

