CarterAppleton / CCScrollNode

A scroll node for Cocos2D that uses a UIScrollView in the background to handle smooth bounces and accelerations.
1 stars 2 forks source link

sample code - zooming in - clarificaiton on use #1

Closed johndpope closed 7 years ago

johndpope commented 11 years ago

CCScrollNode *theScrollNode = [CCScrollNode nodeWithFrame:CGRectMake(0, 0, 320, 480) andContentSize:CGSizeMake(5000,5000)]; [theScrollNode setDelegate:self]; [scene addChild:theScrollNode];

inside the init you have

self.scrollView.hidden = YES; [[[CCDirector sharedDirector] view] addSubview:self.scrollView ];

firstly - I commented out the first line - which then makes shows the scrollview show up.

Then the scrollview is above the cocos2d scene. I tried switching the order or adding children - but think I'm missing something.

Do I need to hang all the children nodes off this class? are you trying to pass the overlapping touches into cocos2d scene so a psuedo view can be made? perhaps a simple example would help.

also the scrolling / zooming in doesn't bite. still debugging that now. Was this class not designed to support zooming / pinching gesture?

johndpope commented 11 years ago

so - if I'm not mistaken - this class just rips out the mechanics of the uiscrollview / a transparent view but doesn't allow adding subviews. It's just offseting the subnode by the scrolling offset.

CGPoint offset = ccp(-scrollView.contentOffset.x,scrollView.contentOffset.y);
self.subnode.position = offset;

if(self.delegate)
    [self.delegate ccScrollNode:self didScrollWithOffset:offset];

so is it necessary to do a lot of pointInside calls to determine when to pass the touches onto the scene ? That could get very complicated very fast.

Hit Testing in a View – hitTest:withEvent: – pointInside:withEvent:

CarterAppleton commented 11 years ago

The addChild method is overwritten so all children and children of the subnode- that way whenever scrolling occurs, the scrollLayer just has to move the subnode and all those children move too.

For when I've used it, it works out fine for cocos. If you add a CCMenu to the scrolllayer, whenever an CCMenuItem comes into view it is selectable.

If you're trying to find the actual position of elements in the scrolllayer, just convert their positions using convertToWorldSpace, which applies all the translations (the subnodes position and such) to give you it's visible position on screen.