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) |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
I found another way to do what i wanted, i used the GL_SCISSOR_TEST in the function called visit which is called when i want to draw my ScrollLayer. Like that : void CCScrollLayer::visit()
{ if it can help someone else ! |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
Well now i put some menu item in a menu in the Scrollable layers, but when i begin the scrolling on this items, it doesn't work.. how can i make it to work ? Best regards! |
||||
| Steven J | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Steven J about 1 year ago
The above code has many problems, especially for C++. I created a more C++ version, and fixed all the missing variables. I took away paging, but it should be easy to add back in as well. Here's the header: CCScrollLayer.h - Corrected headers (5.8 kB) |
||||
| Steven J | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Steven J about 1 year ago
and cpp CCScrollLayer.cpp (2.6 kB) |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
Sorry but i tried your solution and that doesn't work.. may have i did a mistake, but when i created layers, they all overlap .. Did someone found a solution for my previous problem ? -> Thanks |
||||
| Steven J | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Steven J about 1 year ago
One more problem! Create the onExit function and comment out this line from the destructor, and move it to that (otherwise the destructor is not called): void CCScrollLayer::onExit()
{ The destructor is not called until it's removed as a delegate (this follows the same way iPhone SDK would do it)... except that destructors aren't a part of iOs native. Valentin, stop using CCMenuItems and use the CCScrollLayerButton. Menu Items do not work, I learned that the hard way as well. If you do not do the fix above, the scroll view will continue taking touches. And remember to set the maximum scroll height after creating the scroll layer: Also, itemsArray is used like this: CCArray itemsArray = CCArray::array();
That's an almost fully-working example. Also, you can add things other than ccScrollLayerButtons, but they're the only things that directly respond to input. Good luck |
||||
| leo leo | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by leo leo about 1 year ago
Thanks for all the feedback and fixes. |
||||
| Steven J | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Steven J about 1 year ago
Here's a bouncing one, it could use some tweaking to make it easier to get natural, it's based on distances and time helpers. (note, this is just all the touches methods for the ccScrollView) If you're not using pages, feel free to paste this ver: @ void CCScrollLayer::ccTouchMoved(CCTouch *touch, CCEvent *withEvent)
{
void CCScrollLayer::ccTouchEnded(CCTouch * touch, CCEvent * withEvent)
{
void CCScrollLayer::ccTouchCancelled(CCTouch* pTouch, CCEvent* pEvent)
{ void CCScrollLayer::onExit()
{ void CCScrollLayer::bounceToPosition(CCPoint toPos)
{
@ |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C about 1 year ago
I'm sorry but I tried replacing the "menu item" by the CCScrollLayerButton by adding many scrollLayerButton in a single layer, and I have a lot of problem and I do not see how ... I want to do a function that loads all ScrollButton I need and loads it into a CCScrollLayer but I can not do it .. Can you help me please .. it's urgent .. Thanks |
||||
| Steven J | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Steven J about 1 year ago
Valentin, I'm guessing you're still adding them to a CCMenu? The weird part about the scroll layer is, you do not add a ccMneu, only use the buttons. So normally you would do this (to something else) BUT in the scrollLayer you just do this: CCScrollLayerButton * sButton = ... Aside from adding the "real code", that's all you need. If your input isn't working, something else is wrong. If you know Cocos2d, then it should be easy. Try learning Cocos2D and it'll give you examples of how to properly add/remove these things. Also, iOS memory management rules apply too, seriously learn those and basic Cocos2D and this should be easy to do. I don't see why you're using the scissorTest right now. Make sure your memory is being handled right. And ensure everything is in the correct spot ccp(0,0) is the lower-left. |
||||
| Valentin C | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Valentin C 11 months ago
Hi, i come back a little late.. but I don't have the function "CCArray *a = CCArray::arrayWithItem(sButton) ... so how can i do that ? Thanks PS: I'm trainee and i'm on a Cocos2D-X project which use the "scissorTest" so i have to learn many Cocos class very quickly .. that's why i need help ^^! |
||||
| blue eur | RE: UIScrollView solution for cocos2d-x | ||||
|
Great classes, thanks ! |
||||
| Trần Vũ | RE: UIScrollView solution for cocos2d-x | ||||
|
i have a solution. when touchmove, you send to CCDirector view a event "touchesEnded". In my case, it's true. sorry for my english. contact with me if you need ([email protected]) |
||||
| Emilio Exposito | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Emilio Exposito 8 months ago
Hello!!! I have a problem using these classes, I hope someone can help me, I spent two days with the issue and I have been not able to get it working. Let me explain the case, I am using these classes to show a list of users with a vertical scroll, it appears in the screen and it can be moved up and down, but the problem is that the visible space is a very small region in the screen and the list of users is showed from the last element so I need to scroll down the list to see the first element... Does anyone have a example with a vertical scroll? I found some examples using this class but every of them is with a horizontal scroll... Thanks in advance!! |
||||
| Ron Mobi | RE: UIScrollView solution for cocos2d-x | ||||
|
Hi, Emilio, here examples of our vertical scroll. CCScrollLayer.cpp (4.8 kB) CCScrollLayer.h (1.4 kB) |
||||
| Emilio Exposito | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Emilio Exposito 8 months ago
WOW!!! Thanks for your quickly answer!!! Sure it will help me. |
||||
| Aparajita kulkarni | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Aparajita kulkarni 8 months ago
Hi, I am using cocos2d-x with html5. I have lot of text added to a layer. I want that text to be within layer boundaries and layer should have scrolling option to view other text.I want to use CCScrollLayer class. How can I add this CCScrollLayer.h file in my application? or I can say how can i load this .h file through cocos2d.js file? Please let me know the solution. Regards, |
||||
| Aparajita kulkarni | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Aparajita kulkarni 8 months ago
Hi, I am using cocos2dx-html5 for my project. I want scrolling option for my layer. Can any of you please suggest me the solution. The above solution will not work for me. becoz of header file i cannot include in my project, As I am developing on only js files. please let me know the solution as fast as posible. Thanks in advance. Waiting for solution. |
||||
| S O | RE: UIScrollView solution for cocos2d-x | ||||
|
hi there. |
||||
| Herman Jakobi | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Herman Jakobi 6 months ago
Updated this scroll layer for Cocos2d-x V2.x - cleaned up some stuff too. Enjoy! ScrollLayerPages.zip (4 kB) |
||||
| Adi Fly | RE: UIScrollView solution for cocos2d-x | ||||
|
Hello I'm trying to use the CCScrollView, but I don't understand the way I need to set the content size and the position. Thanks! |
||||
| Maksim Shamihulau | RE: UIScrollView solution for cocos2d-x | ||||
|
Added by Maksim Shamihulau 3 months ago
Adi Fly wrote:
Try to increase/decrease parameters (x coordinate) in cc.ScrollView.create(new cc.Size(800, 480), container) and/or scrollView.setContentSize(new cc.Size(800, 480)) and you will see how it easily works. |
« Previous 1 2 (26-47/47)

