How to resize CCScrollLayer content? (extension class cocos2d)

I am currently using the CCScrollLayer class (in cocos2d extension classes) to implement a menu system. It works fine, but I would like to have other buttons on the screen, and the scrollable area is the whole screen by default.

I tried messing around with the size of the content, but not with the cubes. After some reading, I found that the content size is set to the screen size for CCLayers behavior. The user suggested wrapping it in CCNode and scaling it, but that didn't help.

Any suggestions or sample code? I should think that this should be possible.

+4
source share
3 answers

Thank you all for your help, unfortunately, it seems that you cannot resize CCLayer (or contentSize does not affect touch events) without rewriting basically a lot of code.

However, I found a workaround that seems to work. In ccTouch, events started and moved, I checked my desired borders after converting my UITouch to cocos2D space. If they are not within my borders, I return, and in the event of a move, I manually call TouchEnded. TouchEnded also checks the start point of the affected point, and if it is out of bounds, it ignores it.

Things seem to work as they please. I will write additional information if I find it. Thanks again to everyone.

0
source

CAScrollLayer is surprisingly simple, which can be confusing.

Just add a content layer to it:

 [_scrollLayer addSublayer:_contentLayer]; 

To set the rectangle, you want to be visible on the screen, set the borders or frame of the scroll layer:

 [_scrollLayer setBounds:visibleBounds]; 

Set the content size accordingly. The size of the content can be larger or smaller, it does not matter.

 [_contentLayer setBounds:currentContextBounds]; 

If the content is larger and you want to scroll to a specific point, use the scrollToPoint: or scrollToRect: methods of the scroll layer.

If necessary, you need to implement your own scroll indicators, columns, etc.

0
source

Although I use table view rather than scrolling, both have the same parent element [scroll view doh]. Did you enable clipToBounds after setting the size of the content?

I would recommend using this constructor:

 /** * Init this object with a given size to clip its content. * * @param size view size * @return initialized scroll view object */ - (id)initWithViewSize:(CGSize)size; 
0
source

Source: https://habr.com/ru/post/1379591/


All Articles